Skip to content

Commit

Permalink
Merge pull request #246 from rayrayndwiga/master
Browse files Browse the repository at this point in the history
PS: Required fixes to track more information on bookings and two new reports
  • Loading branch information
dbca-asi committed Nov 9, 2017
2 parents 4320926 + f6d8c31 commit 3ef7de0
Show file tree
Hide file tree
Showing 25 changed files with 619 additions and 91 deletions.
1 change: 1 addition & 0 deletions ledger/payments/bpay/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def record_txn(row,_file):
type = row[1],
cheque_num = row[3],
crn = row[4],
original_crn = row[4],
txn_ref = row[5],
service_code = row[6],
p_instruction_code = row[7],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2017-11-07 00:49
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bpay', '0011_parkstay_rebase'),
]

operations = [
migrations.AddField(
model_name='bpaytransaction',
name='original_crn',
field=models.CharField(blank=True, help_text=b'Customer Referencer Number', max_length=20, null=True),
),
]
1 change: 1 addition & 0 deletions ledger/payments/bpay/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class BpayTransaction(models.Model):
type = models.CharField(max_length=3,choices=TRANSACTION_TYPE, help_text='Indicates whether it is a credit or debit item',validators=[MinLengthValidator(3)],)
cheque_num = models.IntegerField(default=0, help_text='Number of cheques in deposit')
crn = models.CharField(max_length=20,help_text='Customer Referencer Number')
original_crn = models.CharField(null=True,blank=True,max_length=20,help_text='Customer Referencer Number')
txn_ref = models.CharField(max_length=21, help_text='Transaction Reference Number',validators=[MinLengthValidator(12)])
service_code = models.CharField(max_length=7, help_text='Unique identification for a service provider realting to a bill.', validators=[MinLengthValidator(1)])
p_instruction_code = models.CharField(max_length=2,choices=PAYMENT_INSTRUCTION_CODES, help_text='Payment instruction method.',validators=[MinLengthValidator(2)])
Expand Down
1 change: 1 addition & 0 deletions ledger/payments/bpoint/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def _create_txn(self,action,crn1,amount,amount_original,amount_surcharge,
txn = BpointTransaction.objects.create(
action=action,
crn1=crn1,
original_crn1=crn1,
amount=self.convert_amount(amount),
amount_original=self.convert_amount(amount_original),
amount_surcharge=self.convert_amount(amount_surcharge),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2017-11-07 00:49
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bpoint', '0011_auto_20171026_1630'),
]

operations = [
migrations.AddField(
model_name='bpointtransaction',
name='original_crn1',
field=models.CharField(blank=True, help_text='Reference for the order that the transaction was made for', max_length=50, null=True),
),
]
1 change: 1 addition & 0 deletions ledger/payments/bpoint/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BpointTransaction(models.Model):
amount_surcharge = models.DecimalField(default=0,decimal_places=2,max_digits=12)
cardtype = models.CharField(max_length=2, choices=CARD_TYPES, blank=True, null=True)
crn1 = models.CharField(max_length=50, help_text='Reference for the order that the transaction was made for')
original_crn1 = models.CharField(null=True,blank=True,max_length=50, help_text='Reference for the order that the transaction was made for')
response_code = models.CharField(max_length=50)
response_txt = models.CharField(max_length=128)
receipt_number = models.CharField(max_length=50)
Expand Down
74 changes: 69 additions & 5 deletions parkstay/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
AccountsAddressSerializer,
ParkEntryRateSerializer,
ReportSerializer,
BookingSettlementReportSerializer,
UserSerializer,
UserAddressSerializer,
ContactSerializer as UserContactSerializer,
Expand Down Expand Up @@ -213,7 +214,10 @@ def open_close(self, request, format='json', pk=None):
except serializers.ValidationError:
raise
except ValidationError as e:
raise serializers.ValidationError(repr(e.error_dict))
if hasattr(e,'error_dict'):
raise serializers.ValidationError(repr(e.error_dict))
else:
raise serializers.ValidationError(repr(e[0].encode('utf-8')))
except Exception as e:
raise serializers.ValidationError(str(e))

Expand Down Expand Up @@ -576,7 +580,10 @@ def open_close(self, request, format='json', pk=None):
print(traceback.print_exc())
raise
except ValidationError as e:
raise serializers.ValidationError(repr(e.error_dict))
if hasattr(e,'error_dict'):
raise serializers.ValidationError(repr(e.error_dict))
else:
raise serializers.ValidationError(repr(e[0].encode('utf-8')))
except Exception as e:
print(traceback.print_exc())
raise serializers.ValidationError(str(e[0]))
Expand Down Expand Up @@ -780,7 +787,7 @@ def stay_history(self, request, format='json', pk=None):
queryset = CampgroundStayHistory.objects.filter(range_end__range = (start,end), range_start__range=(start,end) ).order_by("range_start")[:5]
serializer = CampgroundStayHistorySerializer(queryset,many=True,context={'request':request},method='get')
else:
serializer = CampgroundStayHistorySerializer(self.get_object().stay_history,many=True,context={'request':request},method='get')
serializer = CampgroundStayHistorySerializer(self.get_object().stay_history.all().order_by('-range_start'),many=True,context={'request':request},method='get')
res = serializer.data

return Response(res,status=http_status)
Expand Down Expand Up @@ -1569,7 +1576,10 @@ def list(self, request, *args, **kwargs):
bk['amount_paid'] = booking.amount_paid
bk['vehicle_payment_status'] = booking.vehicle_payment_status
bk['refund_status'] = booking.refund_status
bk['cancellation_reason'] = booking.cancellation_reason
bk['is_canceled'] = 'Yes' if booking.is_canceled else 'No'
bk['cancelation_reason'] = booking.cancellation_reason
bk['canceled_by'] = booking.canceled_by.get_full_name() if booking.canceled_by else ''
bk['cancelation_time'] = booking.cancelation_time.strftime('%d/%m/%Y %H:M:%S') if booking.cancelation_time else ''
bk['paid'] = booking.paid
bk['invoices'] = [ i.invoice_reference for i in booking.invoices.all()]
bk['active_invoices'] = [ i.invoice_reference for i in booking.invoices.all() if i.active]
Expand Down Expand Up @@ -1723,7 +1733,7 @@ def destroy(self, request, *args, **kwargs):
if not reason:
raise serializers.ValidationError('A reason is needed before canceling a booking');
booking = self.get_object()
booking.cancelBooking(reason)
booking.cancelBooking(reason,user=request.user)
emails.send_booking_cancelation(booking,request)
serializer = self.get_serializer(booking)
return Response(serializer.data,status=status.HTTP_200_OK)
Expand Down Expand Up @@ -2062,6 +2072,60 @@ def get(self,request,format=None):
except Exception as e:
traceback.print_exc()

class BookingSettlementReportView(views.APIView):
renderer_classes = (JSONRenderer,)

def get(self,request,format=None):
try:
http_status = status.HTTP_200_OK
#parse and validate data
report = None
data = {
"date":request.GET.get('date'),
}
serializer = BookingSettlementReportSerializer(data=data)
serializer.is_valid(raise_exception=True)
filename = 'Booking Settlement Report-{}'.format(str(serializer.validated_data['date']))
# Generate Report
report = reports.booking_bpoint_settlement_report(serializer.validated_data['date'])
if report:
response = HttpResponse(FileWrapper(report), content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="{}.csv"'.format(filename)
return response
else:
raise serializers.ValidationError('No report was generated.')
except serializers.ValidationError:
raise
except Exception as e:
traceback.print_exc()

class BookingReportView(views.APIView):
renderer_classes = (JSONRenderer,)

def get(self,request,format=None):
try:
http_status = status.HTTP_200_OK
#parse and validate data
report = None
data = {
"date":request.GET.get('date'),
}
serializer = BookingSettlementReportSerializer(data=data)
serializer.is_valid(raise_exception=True)
filename = 'Booking Report-{}'.format(str(serializer.validated_data['date']))
# Generate Report
report = reports.bookings_report(serializer.validated_data['date'])
if report:
response = HttpResponse(FileWrapper(report), content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="{}.csv"'.format(filename)
return response
else:
raise serializers.ValidationError('No report was generated.')
except serializers.ValidationError:
raise
except Exception as e:
traceback.print_exc()

class GetProfile(views.APIView):
renderer_classes = [JSONRenderer,]
permission_classes = []
Expand Down
14 changes: 13 additions & 1 deletion parkstay/frontend/parkstay/src/components/booking/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export default {
var json2csv = require('json2csv');
var fields = [...vm.dtHeaders];
fields.splice(vm.dtHeaders.length-1,1);
fields = [...fields,"Adults","Concession","Children","Infants","Regos"]
fields = [...fields,"Adults","Concession","Children","Infants","Regos","Canceled","Cancelation Reason","Cancelation Date","Canceled By"]
fields.splice(3,0,"Email");
fields.splice(4,0,"Phone");
fields.splice(8,0,'Amount Due')
Expand Down Expand Up @@ -528,6 +528,18 @@ export default {
});
}).join(" | ");
break;
case 17:
bk[field] = booking.is_canceled;
break;
case 18:
bk[field] = booking.cancelation_reason;
break;
case 19:
bk[field] = booking.cancelation_time;
break;
case 20:
bk[field] = booking.canceled_by;
break;
}
});
Expand Down
Loading

0 comments on commit 3ef7de0

Please sign in to comment.