Skip to content

Commit

Permalink
refs #78
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Nov 18, 2017
1 parent f78237f commit 6e7b9d6
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 32 deletions.
15 changes: 7 additions & 8 deletions app/Http/Controllers/Customers/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,12 @@ public function show(Invoice $invoice)
*
* @return Response
*/
public function printInvoice($invoice_id)
public function printInvoice(Invoice $invoice)
{
$sub_total = 0;
$tax_total = 0;
$paid = 0;

$invoice = Invoice::where('id', $invoice_id)->first();

foreach ($invoice->items as $item) {
$sub_total += ($item->price * $item->quantity);
$tax_total += ($item->tax * $item->quantity);
Expand All @@ -136,14 +134,12 @@ public function printInvoice($invoice_id)
*
* @return Response
*/
public function pdfInvoice($invoice_id)
public function pdfInvoice(Invoice $invoice)
{
$sub_total = 0;
$tax_total = 0;
$paid = 0;

$invoice = Invoice::where('id', $invoice_id)->first();

foreach ($invoice->items as $item) {
$sub_total += ($item->price * $item->quantity);
$tax_total += ($item->tax * $item->quantity);
Expand Down Expand Up @@ -177,10 +173,13 @@ public function pdfInvoice($invoice_id)
*
* @return Response
*/
public function payment(PaymentRequest $request)
public function payment(Invoice $invoice, PaymentRequest $request)
{
$invoice = Invoice::where(['id' => $request['invoice_id'], 'customer_id' => Auth::user()->customer->id])->first();
if (!$invoice) {
return response()->json(

);
}
// Fire the event to extend the menu
$result = event(new PaymentGatewayConfirm($request['payment_method'], $invoice));

Expand Down
38 changes: 28 additions & 10 deletions app/Utilities/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,54 @@ class Modules

public static function getPaymentMethods()
{
$payment_methods = Cache::get('payment_methods');

$payment_methods = Cache::get('payment_methods.admin');

$customer = auth()->user()->customer;

if ($customer) {
$payment_methods = Cache::get('payment_methods.customer');
}

if (!empty($payment_methods)) {
return $payment_methods;
}

$gateways = array();
$gateways = [];
$methods = [];

// Fire the event to extend the menu
$results = event(new PaymentGatewayListing($gateways));

foreach ($results as $gateways) {
foreach ($gateways as $gateway) {
if ($customer && empty($gateway['customer'])) {
continue;
}

$methods[] = $gateway;
}
}

$sort_order = array();
$sort_order = [];

foreach ($methods as $key => $value) {
$sort_order[$key] = $value['order'];
}
if ($methods) {
foreach ($methods as $key => $value) {
$sort_order[$key] = $value['order'];
}

array_multisort($sort_order, SORT_ASC, $methods);
array_multisort($sort_order, SORT_ASC, $methods);

foreach ($methods as $method) {
$payment_methods[$method['code']] = $method['name'];
foreach ($methods as $method) {
$payment_methods[$method['code']] = $method['name'];
}
}

Cache::put('payment_methods', $payment_methods, Date::now()->addHour(6));
if ($customer) {
Cache::put('payment_methods.customer', $payment_methods, Date::now()->addHour(6));
} else {
Cache::put('payment_methods.admin', $payment_methods, Date::now()->addHour(6));
}

return $payment_methods;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class OfflinePaymentConfirm
*/
public function handle(PaymentGatewayConfirm $event)
{
/*if (strpos($event->gateway, 'offlinepayment') === false) {
return false;
if (strpos($event->gateway, 'offlinepayment') === false) {
return [];
}

return [
'code' => $event->gateway,
'name' => $event->gateway,
'redirect' => false,
'html' => true,
];*/
];
}
}
4 changes: 4 additions & 0 deletions modules/OfflinePayment/Http/Controllers/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function update(Request $request)

$offlinepayment[$key]['code'] = 'offlinepayment.' . $request['code'] . '.' . $method[2];
$offlinepayment[$key]['name'] = $request['name'];
$offlinepayment[$key]['customer'] = $request['customer'];
$offlinepayment[$key]['order'] = $request['order'];
$offlinepayment[$key]['description'] = $request['description'];
}
Expand All @@ -48,6 +49,7 @@ public function update(Request $request)
$offlinepayment[] = array(
'code' => 'offlinepayment.' . $request['code'] . '.' . (count($offlinepayment) + 1),
'name' => $request['name'],
'customer' => $request['customer'],
'order' => $request['order'],
'description' => $request['description']
);
Expand Down Expand Up @@ -83,6 +85,8 @@ public function get(GRequest $request)
$method['code'] = $code[1];

$data = $method;

break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'add_new' => 'Add New',
'edit' => 'Edit: :method',
'code' => 'Code',
'customer' => 'Show to Customer',
'order' => 'Order',
'payment_gateways' => 'Offline Payment Methods',

Expand Down
14 changes: 13 additions & 1 deletion modules/OfflinePayment/Resources/views/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

{{ Form::textGroup('code', trans('offlinepayment::offlinepayment.code'), 'key', ['required' => 'required'], null, 'col-md-12') }}

{{ Form::textGroup('order', trans('offlinepayment::offlinepayment.order'), 'sort', [], 0, 'col-md-12') }}
{{ Form::radioGroup('customer', trans('offlinepayment::offlinepayment.customer'), '', ['required' => 'required'], 0, 'col-md-12') }}

{{ Form::textGroup('order', trans('offlinepayment::offlinepayment.order'), 'sort', [], null, 'col-md-12') }}

{{ Form::textareaGroup('description', trans('general.description')) }}
</div>
Expand Down Expand Up @@ -109,6 +111,9 @@

@push('scripts')
<script type="text/javascript">
var text_yes = '{{ trans('general.yes') }}';
var text_no = '{{ trans('general.no') }}';
$(document).ready(function() {
$('.method-edit').on('click', function() {
var code = $(this).attr('id').replace('edit-', '');
Expand All @@ -134,6 +139,13 @@
$('.col-md-4.no-padding-left .box-header.with-border .box-title').html(json['data']['title']);
$('input[name="name"]').val(json['data']['name']);
$('input[name="code"]').val(json['data']['code']);
if (json['data']['customer']) {
$('#customer_1 input').trigger('click');
} else {
$('#customer_0 input').trigger('click');
}
$('input[name="order"]').val(json['data']['order']);
$('input[name="description"]').val(json['data']['description']);
Expand Down
18 changes: 18 additions & 0 deletions public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ div.required .control-label:not(span):after, td.required:after {
left: 40%;
}

.confirm #loading {
position: inherit;
top: 40%;
left: 40%;
}

#payment-modal .form-group.col-md-6 .help-block {
color : #F00;
}
Expand Down Expand Up @@ -488,3 +494,15 @@ ul.add-new.nav.navbar-nav.pull-left {
background-color: #ffffff;
}
}
/*
.content-wrapper {
overflow: inherit;
}
.main-footer {
bottom: 0;
left: 0;
position: fixed;
right: 0;
z-index: 999;
}*/
15 changes: 8 additions & 7 deletions resources/views/customers/invoices/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@
</div>

<div class="col-sm-2">
{!! Form::select('payment_method', $payment_methods, null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.payment_methods', 1)])])) !!}
@if ($payment_methods)
{!! Form::select('payment_method', $payment_methods, null, array_merge(['id' => 'payment-method', 'class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.payment_methods', 1)])])) !!}
{!! Form::hidden('invoice_id', $invoice->id, []) !!}
<button type="button" id="button-payment" class="btn btn-success">
<i class="fa fa-credit-card"></i>&nbsp; {{ trans('invoices.add_payment') }}
</button>
@else

@endif
</div>
<div class="confirm"></div>
</div>
Expand All @@ -167,9 +168,9 @@
@push('scripts')
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click', '#button-payment', function (e) {
$(document).on('change', '#payment-method', function (e) {
$.ajax({
url: '{{ url("customers/invoices/payment") }}',
url: '{{ url("customers/invoices/" . $invoice->id . "payment") }}',
type: 'POST',
dataType: 'JSON',
data: $('.box-footer input, .box-footer select'),
Expand All @@ -183,7 +184,7 @@
success: function(data) {
$("#payment-modal").modal('hide');
location.reload();
//location.reload();
},
error: function(data){
Expand Down
6 changes: 3 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@
Route::group(['prefix' => 'customers'], function () {
Route::get('/', 'Customers\Dashboard@index');

Route::get('invoices/{id}/print', 'Customers\Invoices@printInvoice');
Route::get('invoices/{id}/pdf', 'Customers\Invoices@pdfInvoice');
Route::post('invoices/payment', 'Customers\Invoices@payment');
Route::get('invoices/{invoice}/print', 'Customers\Invoices@printInvoice');
Route::get('invoices/{invoice}/pdf', 'Customers\Invoices@pdfInvoice');
Route::post('invoices/{invoice}/payment', 'Customers\Invoices@payment');
Route::resource('invoices', 'Customers\Invoices');
Route::resource('payments', 'Customers\Payments');
Route::resource('transactions', 'Customers\Transactions');
Expand Down

0 comments on commit 6e7b9d6

Please sign in to comment.