Added the final missing Voids or Reprints report aslo.
Ready for beta 1. Removed voucher.is_void in favour voucher_type == void
This commit is contained in:
parent
2b04b624b3
commit
b898e26dc6
|
@ -23,6 +23,6 @@
|
|||
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\s-InventoryModifiers.sql
|
||||
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\t-Overview.sql
|
||||
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\u-ProductGroupModifiers.sql
|
||||
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\v-Reprints.sql
|
||||
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\v-Reprints.sql
|
||||
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\w-Settings.sql
|
||||
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < Data\x-VoucherSettlements.sql
|
|
@ -16,7 +16,7 @@ call:copyQuery m-Sections "SELECT 'INSERT INTO sections(id, name) VALUES (''' +
|
|||
call:copyQuery n-Printers "SELECT 'INSERT INTO printers(id, name, address, cut_code) VALUES (''' + CAST(NewID() AS Nvarchar(36)) + ''', ''' + Printer + ''', ''' + Printer + ''', ''' + CutCode + ''');' FROM Test.dbo.PrintLocations GROUP BY Printer, CutCode;"
|
||||
call:copyQuery o-SectionPrinters "SELECT 'INSERT INTO section_printers(id, menu_category_id, section_id, printer_id, copies) VALUES (''' + CAST(PrintLocationID AS Nvarchar(36)) + ''', ' + COALESCE('''' + CAST(ProductGroupID AS Nvarchar(36)) + '''','null') + ', ' + '(select id from sections where name = ''' + Location + ''')' + ', ' + '(select id from printers where name = ''' + Printer + ''')' + ', ' + CAST(Copies AS nvarchar(36)) + ');' FROM Test.dbo.PrintLocations;"
|
||||
|
||||
call:copyQuery p-Vouchers "SELECT 'INSERT INTO vouchers(id, date, pax, user_id, creation_date, last_edit_date, bill_id, food_table_id, customer_id, narration, is_void, void_reason, voucher_type, kot_id) VALUES (''' + CAST(VoucherID AS Nvarchar(36)) + ''', ' + '''' + CONVERT(Nvarchar(36), Date, 126) + ''', ' + COALESCE(CAST(Pax AS Nvarchar(36)), 'null') + ', ''' + CAST(UserID AS Nvarchar(36)) + ''', ' + '''' + CONVERT(Nvarchar(36), CreationDate, 126) + ''', ' + '''' + CONVERT(Nvarchar(36), LastEditDate, 126) + ''', ' + COALESCE(CAST(BillID AS Nvarchar(36)), 'null') + ', ' + '''' + CAST(TableID AS Nvarchar(36)) + ''', ' + '''' + CAST(CustomerID AS Nvarchar(36)) + ''', ' + COALESCE('''' + REPLACE(Narration, '''', '''''') + '''', 'null') + ', ' + CASE WHEN Void = 1 THEN 'true' ELSE 'false' END + ', ' + COALESCE('''' + REPLACE(VoidReason, '''', '''''') + '''', 'null') + ', ' + CASE WHEN Printed = 0 THEN '0' WHEN Void = 1 THEN '5' ELSE CAST(VoucherType AS Nvarchar(36)) END + ', ' + CAST(KotID AS Nvarchar(36)) + ');' FROM Test.dbo.Vouchers;"
|
||||
call:copyQuery p-Vouchers "SELECT 'INSERT INTO vouchers(id, date, pax, user_id, creation_date, last_edit_date, bill_id, food_table_id, customer_id, narration, void_reason, voucher_type, kot_id) VALUES (''' + CAST(VoucherID AS Nvarchar(36)) + ''', ' + '''' + CONVERT(Nvarchar(36), Date, 126) + ''', ' + COALESCE(CAST(Pax AS Nvarchar(36)), 'null') + ', ''' + CAST(UserID AS Nvarchar(36)) + ''', ' + '''' + CONVERT(Nvarchar(36), CreationDate, 126) + ''', ' + '''' + CONVERT(Nvarchar(36), LastEditDate, 126) + ''', ' + COALESCE(CAST(BillID AS Nvarchar(36)), 'null') + ', ' + '''' + CAST(TableID AS Nvarchar(36)) + ''', ' + '''' + CAST(CustomerID AS Nvarchar(36)) + ''', ' + COALESCE('''' + REPLACE(Narration, '''', '''''') + '''', 'null') + ', ' + COALESCE('''' + REPLACE(VoidReason, '''', '''''') + '''', 'null') + ', ' + CASE WHEN Printed = 0 THEN '0' WHEN Void = 1 THEN '5' ELSE CAST(VoucherType AS Nvarchar(36)) END + ', ' + CAST(KotID AS Nvarchar(36)) + ');' FROM Test.dbo.Vouchers;"
|
||||
call:copyQuery q-Kots "SELECT 'INSERT INTO kots(id, voucher_id, code, food_table_id, date, user_id) VALUES (''' + CAST(KotID AS Nvarchar(36)) + ''', ' + '''' + CAST(VoucherID AS Nvarchar(36)) + '''' + ', ' + CAST(Code AS Nvarchar(36)) + ', ' + '''' + CAST(TableID AS Nvarchar(36)) + '''' + ', ' + '''' + CONVERT(Nvarchar(36), Date, 126) + ''', ''' + CAST(UserID AS Nvarchar(36)) + ''');' FROM Test.dbo.Kots;"
|
||||
call:copyQuery r-Inventories "SELECT 'INSERT INTO inventories(id, kot_id, product_id, sort_order, quantity, price, is_happy_hour, tax_rate, tax_id, discount) VALUES (''' + CAST(InventoryID AS Nvarchar(36)) + ''', ' + '''' + CAST(KotID AS Nvarchar(36)) + '''' + ', ' + '''' + CAST(ProductID AS Nvarchar(36)) + '''' + ', ' + CAST(SortOrder AS Nvarchar(36)) + ', ' + CAST(Quantity AS Nvarchar(36)) + ', ' + CAST(Price AS Nvarchar(36)) + ', ' + CASE WHEN IsHappyHour = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(VatRate AS Nvarchar(36)) + ', ' + '''' + CAST(VatID AS Nvarchar(36)) + '''' + ', ' + CAST(Discount AS Nvarchar(36)) + ');' FROM Test.dbo.Inventories;"
|
||||
call:copyQuery s-InventoryModifiers "SELECT 'INSERT INTO inventory_modifiers(id, inventory_id, modifier_id, price) VALUES (''' + CAST(InventoryModifierID AS Nvarchar(36)) + ''', ' + '''' + CAST(InventoryID AS Nvarchar(36)) + '''' + ', ' + '''' + CAST(ModifierID AS Nvarchar(36)) + '''' + ', 0);' FROM Test.dbo.InventoryModifiers;"
|
||||
|
|
|
@ -114,7 +114,6 @@ class Voucher(Base):
|
|||
)
|
||||
customer_id = Column("customer_id", GUID(), ForeignKey("customers.id"))
|
||||
narration = Column("narration", Unicode(1000), nullable=False)
|
||||
is_void = Column("is_void", Boolean, nullable=False)
|
||||
void_reason = Column("void_reason", Unicode(255))
|
||||
_voucher_type = Column("voucher_type", Integer, nullable=False)
|
||||
user_id = Column("user_id", GUID(), ForeignKey("users.id"), nullable=False)
|
||||
|
@ -171,7 +170,6 @@ class Voucher(Base):
|
|||
self.food_table_id = food_table_id
|
||||
self.customer_id = customer_id
|
||||
self.narration = ""
|
||||
self.is_void = False
|
||||
self.void_reason = None
|
||||
self.voucher_type = voucher_type
|
||||
self.user_id = user_id
|
||||
|
|
|
@ -366,6 +366,7 @@ def includeme(config):
|
|||
config.add_route("v1_bill_settlement_report", "/v1/bill-settlement-report")
|
||||
config.add_route("v1_beer_consumption_report", "/v1/beer-consumption-report")
|
||||
config.add_route("v1_discount_report", "/v1/discount-report")
|
||||
config.add_route("v1_voids_reprints_report", "/v1/voids-reprints-report")
|
||||
# Done till here
|
||||
|
||||
config.add_route("customer", "/Customer.json")
|
||||
|
@ -387,8 +388,6 @@ def includeme(config):
|
|||
config.add_route("v1_bills_new", "/v1/bills/new")
|
||||
config.add_route("v1_bills_id", "/v1/bills/{id}")
|
||||
|
||||
config.add_route("quantity_sold", "/QuantitySold.json")
|
||||
|
||||
config.add_route("reprint", "/Reprint.json")
|
||||
config.add_route("reprint_report", "/ReprintReport.json")
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from datetime import datetime, timedelta
|
|||
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Settlement, SettleOption, Voucher
|
||||
from barker.models import Settlement, SettleOption, Voucher, VoucherType
|
||||
from barker.models.validation_exception import ValidationError
|
||||
from barker.views.reports import get_start_date, get_finish_date
|
||||
|
||||
|
@ -34,7 +34,7 @@ def bill_details(request):
|
|||
|
||||
report = []
|
||||
for item in vouchers:
|
||||
if item.is_void:
|
||||
if item.voucher_type == VoucherType.VOID:
|
||||
amount = (
|
||||
next(
|
||||
s.amount
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
import datetime
|
||||
|
||||
from pyramid.httpexceptions import HTTPForbidden
|
||||
from pyramid.view import view_config
|
||||
from sqlalchemy import func
|
||||
|
||||
from barker.models import Inventory, Kot, Product, MenuCategory, Settlement, SettleOption, Voucher
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='quantity_sold', renderer='json', permission='Sales Detail',
|
||||
request_param=('s', 'f'))
|
||||
def quantity_sold(request):
|
||||
start_date = datetime.datetime.strptime(request.GET['s'], '%d-%b-%Y %H:%M')
|
||||
finish_date = datetime.datetime.strptime(request.GET['f'], '%d-%b-%Y %H:%M')
|
||||
|
||||
if (datetime.date.today() - start_date.date()).days > 5 and 'Accounts Audit' not in request.effective_principals:
|
||||
raise HTTPForbidden("Accounts Audit")
|
||||
|
||||
sold = q(start_date, finish_date, [
|
||||
SettleOption.CASH(),
|
||||
SettleOption.CREDIT_CARD(),
|
||||
SettleOption.BILL_TO_COMPANY(),
|
||||
SettleOption.STAFF()
|
||||
], request.dbsession)
|
||||
|
||||
nc = q(start_date, finish_date, [
|
||||
SettleOption.NO_CHARGE()
|
||||
], request.dbsession)
|
||||
|
||||
output = [{
|
||||
'ProductID': str(i[0]),
|
||||
'Name': i[1],
|
||||
'IsHappyHour': i[2],
|
||||
'Sale': i[3]
|
||||
} for i in sold]
|
||||
for id, name, hh, qty in nc:
|
||||
i = next((x for x in output if x['ProductID'] == str(id) and x['IsHappyHour'] == hh), None)
|
||||
if i is None:
|
||||
output.append({'ProductID': str(id), 'Name': name, 'IsHappyHour': hh, 'NC': qty})
|
||||
else:
|
||||
i['NC'] = qty
|
||||
return output
|
||||
|
||||
|
||||
def q(start_date, finish_date, options, dbsession):
|
||||
return dbsession.query(
|
||||
Product.id, Product.full_name, Inventory.is_happy_hour, func.sum(Inventory.quantity)
|
||||
).join(Voucher.kots).join(Kot.inventories).join(Inventory.product).join(Product.menu_category).filter(
|
||||
Voucher.date >= start_date,
|
||||
Voucher.date <= finish_date,
|
||||
Voucher.is_void == False,
|
||||
Voucher.settlements.any(Settlement.settled.in_(options))
|
||||
).group_by(
|
||||
Product.id, Product.full_name, Inventory.is_happy_hour, MenuCategory.name, MenuCategory.group_type
|
||||
).order_by(
|
||||
MenuCategory.group_type, MenuCategory.name, Product.full_name, Inventory.is_happy_hour
|
||||
).all()
|
|
@ -1,62 +0,0 @@
|
|||
import datetime
|
||||
|
||||
from pyramid.httpexceptions import HTTPForbidden
|
||||
from pyramid.view import view_config
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
from barker.models import Reprint, Settlement, SettleOption, Voucher
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='reprint_report', renderer='json',
|
||||
permission='Void or Reprinted Bill Report', request_param=('s', 'f'))
|
||||
def reprint_report(request):
|
||||
start_date = datetime.datetime.strptime(request.GET['s'], '%d-%b-%Y %H:%M')
|
||||
finish_date = datetime.datetime.strptime(request.GET['f'], '%d-%b-%Y %H:%M')
|
||||
|
||||
if (datetime.date.today() - start_date.date()).days > 5 and 'Accounts Audit' not in request.effective_principals:
|
||||
raise HTTPForbidden("Accounts Audit")
|
||||
|
||||
# TODO: Should be left outer join in case some bill is missing the settlements
|
||||
voids = []
|
||||
void_q = request.dbsession.query(
|
||||
Voucher
|
||||
).options(
|
||||
joinedload(Voucher.settlements, innerjoin=True).joinedload(Settlement.settle_option, innerjoin=True),
|
||||
joinedload(Voucher.customer, innerjoin=True)
|
||||
).filter(
|
||||
Voucher.date >= start_date,
|
||||
Voucher.date <= finish_date,
|
||||
Voucher.is_void == True
|
||||
).order_by(
|
||||
Voucher.voucher_type
|
||||
).order_by(
|
||||
Voucher.bill_id
|
||||
).all()
|
||||
|
||||
for item in void_q:
|
||||
voids.append({
|
||||
'Date': item.date.strftime('%d-%b-%Y %H:%M:%S'),
|
||||
'BillID': item.full_bill_id,
|
||||
'Settlement': "Void: {0}".format(item.void_reason),
|
||||
'Amount': round(next(
|
||||
s.amount for s in item.settlements if s.settled == SettleOption.AMOUNT()
|
||||
) * -1, 2)
|
||||
})
|
||||
|
||||
reprints = []
|
||||
reprint_q = request.dbsession.query(Reprint).filter(
|
||||
Reprint.date >= start_date,
|
||||
Reprint.date <= finish_date
|
||||
).all()
|
||||
|
||||
for item in reprint_q:
|
||||
reprints.append({
|
||||
'Date': item.date.strftime('%d-%b-%Y %H:%M:%S'),
|
||||
'BillID': item.voucher.full_bill_id,
|
||||
'Settlement': "Reprinted by {0}".format(item.user.name),
|
||||
'Amount': round(next(
|
||||
s.amount for s in item.voucher.settlements if s.settled == SettleOption.AMOUNT()
|
||||
) * -1, 2)
|
||||
})
|
||||
|
||||
return voids + reprints
|
|
@ -0,0 +1,65 @@
|
|||
from datetime import datetime, timedelta
|
||||
|
||||
from pyramid.view import view_config
|
||||
|
||||
from barker.models import Settlement, SettleOption, Voucher, VoucherType, Reprint
|
||||
from barker.models.validation_exception import ValidationError
|
||||
from barker.views.reports import get_start_date, get_finish_date
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_voids_reprints_report",
|
||||
renderer="json",
|
||||
permission="Void or Reprinted Bill Report",
|
||||
)
|
||||
def voids_reprints_report_view(request):
|
||||
start_date = get_start_date(request.GET.get("s", None))
|
||||
finish_date = get_finish_date(request.GET.get("f", None))
|
||||
|
||||
if (
|
||||
datetime.today() - start_date.replace(hour=0)
|
||||
).days > 5 and "Accounts Audit" not in request.effective_principals:
|
||||
raise ValidationError("Accounts Audit")
|
||||
|
||||
return {
|
||||
"startDate": start_date.date().strftime("%d-%b-%Y"),
|
||||
"finishDate": (finish_date - timedelta(days=1)).date().strftime("%d-%b-%Y"),
|
||||
"amounts": voids_reprints_report(start_date, finish_date, request.dbsession),
|
||||
}
|
||||
|
||||
|
||||
def voids_reprints_report(start_date, finish_date, dbsession):
|
||||
vouchers = (
|
||||
dbsession.query(Voucher, Settlement.amount * -1)
|
||||
.join(Voucher.settlements)
|
||||
.filter(Voucher.date >= start_date, Voucher.date <= finish_date, Voucher.voucher_type == VoucherType.VOID.value, Settlement.settled == SettleOption.AMOUNT())
|
||||
.order_by(Voucher.date)
|
||||
.all()
|
||||
)
|
||||
print(str(vouchers))
|
||||
report = []
|
||||
for item, amount in vouchers:
|
||||
report.append(
|
||||
{
|
||||
"date": item.date.strftime("%d-%b-%Y %H:%M:%S"),
|
||||
"billId": item.full_bill_id,
|
||||
"settlement": f"Void: {item.void_reason}",
|
||||
"amount": round(amount, 2),
|
||||
}
|
||||
)
|
||||
reprints = dbsession.query(Reprint).filter(
|
||||
Reprint.date >= start_date,
|
||||
Reprint.date <= finish_date
|
||||
).all()
|
||||
|
||||
for item in reprints:
|
||||
report.append({
|
||||
'date': item.date.strftime('%d-%b-%Y %H:%M:%S'),
|
||||
'billId': item.voucher.full_bill_id,
|
||||
'settlement': f"Reprinted by {item.user.name}",
|
||||
'Amount': round(next(
|
||||
s.amount for s in item.voucher.settlements if s.settled == SettleOption.AMOUNT()
|
||||
) * -1, 2)
|
||||
})
|
||||
return report
|
|
@ -58,7 +58,7 @@ def check_permissions(item, voucher_type, permissions):
|
|||
if item.voucher_type != VoucherType.KOT and voucher_type == VoucherType.KOT:
|
||||
raise ValidationFailure("This Bill is already printed\nCannot add a Kot to it.")
|
||||
|
||||
if item.is_void:
|
||||
if item.voucher_type == VoucherType.VOID:
|
||||
raise ValidationFailure(
|
||||
"This Bill is already void.\nReason: {0}".format(item.void_reason)
|
||||
)
|
||||
|
|
|
@ -98,7 +98,6 @@ def voucher_info(item):
|
|||
"customer": {"id": item.customer_id, "name": item.customer.name} if item.customer is not None else {},
|
||||
"settlements": [],
|
||||
"narration": item.narration,
|
||||
"void": item.is_void,
|
||||
"voidReason": item.void_reason,
|
||||
"voucherType": item.voucher_type.name,
|
||||
"kotId": item.kot_id,
|
||||
|
|
|
@ -93,6 +93,10 @@ const routes: Routes = [
|
|||
path: 'users',
|
||||
loadChildren: () => import('./users/users.module').then(mod => mod.UsersModule)
|
||||
},
|
||||
{
|
||||
path: 'voids-reprints-report',
|
||||
loadChildren: () => import('./voids-reprints-report/voids-reprints-report.module').then(mod => mod.VoidsReprintsReportModule)
|
||||
},
|
||||
{path: 'login', component: LoginComponent},
|
||||
{path: 'logout', component: LogoutComponent},
|
||||
{path: '', component: HomeComponent},
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
<mat-card fxLayout="column" class="square-button" matRipple *ngIf="auth.hasPermission('Beer Consumption')" [routerLink]="['/', 'beer-consumption-report']">
|
||||
<h3 class="item-name">Beer Consumption Report</h3>
|
||||
</mat-card>
|
||||
<mat-card fxLayout="column" class="square-button" matRipple *ngIf="auth.hasPermission('Void or Reprinted Bill Report')" [routerLink]="['/', 'voids-reprints-report']">
|
||||
<h3 class="item-name">Voids and Reprints Report</h3>
|
||||
</mat-card>
|
||||
<mat-card fxLayout="column" class="square-button" matRipple *ngIf="auth.hasPermission('Discount Report')" [routerLink]="['/', 'discount-report']">
|
||||
<h3 class="item-name">Discount Report</h3>
|
||||
</mat-card>
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { VoidsReprintsReportItem } from './voids-reprints-report';
|
||||
|
||||
|
||||
export class VoidsReprintsReportDataSource extends DataSource<VoidsReprintsReportItem> {
|
||||
|
||||
constructor(public data: VoidsReprintsReportItem[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<VoidsReprintsReportItem[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {VoidsReprintsReportResolver} from './voids-reprints-report-resolver.service';
|
||||
|
||||
describe('VoidsReprintsReportResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [VoidsReprintsReportResolver]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([VoidsReprintsReportResolver], (service: VoidsReprintsReportResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -0,0 +1,20 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {VoidsReprintsReport} from './voids-reprints-report';
|
||||
import {VoidsReprintsReportService} from './voids-reprints-report.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class VoidsReprintsReportResolver implements Resolve<VoidsReprintsReport> {
|
||||
|
||||
constructor(private ser: VoidsReprintsReportService) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<VoidsReprintsReport> {
|
||||
const startDate = route.queryParamMap.get('startDate') || null;
|
||||
const finishDate = route.queryParamMap.get('finishDate') || null;
|
||||
return this.ser.get(startDate, finishDate);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import {VoidsReprintsReportRoutingModule} from './voids-reprints-report-routing.module';
|
||||
|
||||
describe('VoidsReprintsReportRoutingModule', () => {
|
||||
let pvoidsReprintsReportRoutingModule: VoidsReprintsReportRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
pvoidsReprintsReportRoutingModule = new VoidsReprintsReportRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(pvoidsReprintsReportRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,37 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { VoidsReprintsReportResolver } from './voids-reprints-report-resolver.service';
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
import { VoidsReprintsReportComponent } from './voids-reprints-report.component';
|
||||
|
||||
const VoidsReprintsReportRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: VoidsReprintsReportComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Void or Reprinted Bill Report' // rename to Void and Reprinted Bill Report
|
||||
},
|
||||
resolve: {
|
||||
info: VoidsReprintsReportResolver
|
||||
},
|
||||
runGuardsAndResolvers: 'always'
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(VoidsReprintsReportRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
VoidsReprintsReportResolver
|
||||
]
|
||||
})
|
||||
export class VoidsReprintsReportRoutingModule {
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
.right {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Voids and Reprints Report</mat-card-title>
|
||||
<button mat-button mat-icon-button (click)="exportCsv()">
|
||||
<mat-icon>save_alt</mat-icon>
|
||||
</button>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px"
|
||||
fxLayoutAlign="space-around start">
|
||||
<mat-form-field fxFlex="40">
|
||||
<input matInput [matDatepicker]="startDate" (focus)="startDate.open()" placeholder="Start Date"
|
||||
formControlName="startDate" autocomplete="off">
|
||||
<mat-datepicker-toggle matSuffix [for]="startDate"></mat-datepicker-toggle>
|
||||
<mat-datepicker #startDate></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="40">
|
||||
<input matInput [matDatepicker]="finishDate" (focus)="finishDate.open()" placeholder="Finish Date"
|
||||
formControlName="finishDate" autocomplete="off">
|
||||
<mat-datepicker-toggle matSuffix [for]="finishDate"></mat-datepicker-toggle>
|
||||
<mat-datepicker #finishDate></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<button fxFlex="20" mat-raised-button color="primary" (click)="show()">Show</button>
|
||||
</div>
|
||||
</form>
|
||||
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
||||
|
||||
<!-- Date Column -->
|
||||
<ng-container matColumnDef="date">
|
||||
<mat-header-cell *matHeaderCellDef>Time</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.date}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Bill ID Column -->
|
||||
<ng-container matColumnDef="billId">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Bill ID</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{row.billId}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Amount Column -->
|
||||
<ng-container matColumnDef="amount">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Amount</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{row.amount | number:'1.2-2'}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Settlement Column -->
|
||||
<ng-container matColumnDef="settlement">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Settlement</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{row.settlement}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
</mat-table>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
|
@ -0,0 +1,25 @@
|
|||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {VoidsReprintsReportComponent} from './voids-reprints-report.component';
|
||||
|
||||
describe('VoidsReprintsReportComponent', () => {
|
||||
let component: VoidsReprintsReportComponent;
|
||||
let fixture: ComponentFixture<VoidsReprintsReportComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [VoidsReprintsReportComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(VoidsReprintsReportComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,90 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { VoidsReprintsReportDataSource } from './voids-reprints-report-datasource';
|
||||
import { VoidsReprintsReport } from './voids-reprints-report';
|
||||
import { ToCsvService } from '../shared/to-csv.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-voids-reprints-report',
|
||||
templateUrl: './voids-reprints-report.component.html',
|
||||
styleUrls: ['./voids-reprints-report.component.css']
|
||||
})
|
||||
export class VoidsReprintsReportComponent implements OnInit {
|
||||
dataSource: VoidsReprintsReportDataSource;
|
||||
form: FormGroup;
|
||||
info: VoidsReprintsReport;
|
||||
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['date', 'billId', 'amount', 'settlement'];
|
||||
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private toCsv: ToCsvService
|
||||
) {
|
||||
this.createForm();
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { info: VoidsReprintsReport }) => {
|
||||
this.info = data.info;
|
||||
this.form.setValue({
|
||||
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
|
||||
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate()
|
||||
});
|
||||
this.dataSource = new VoidsReprintsReportDataSource(this.info.amounts);
|
||||
});
|
||||
}
|
||||
|
||||
show() {
|
||||
const info = this.getInfo();
|
||||
this.router.navigate(['voids-reprints-report'], {
|
||||
queryParams: {
|
||||
startDate: info.startDate,
|
||||
finishDate: info.finishDate
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
startDate: '',
|
||||
finishDate: ''
|
||||
});
|
||||
}
|
||||
|
||||
getInfo(): VoidsReprintsReport {
|
||||
const formModel = this.form.value;
|
||||
|
||||
return {
|
||||
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
|
||||
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY')
|
||||
};
|
||||
}
|
||||
|
||||
exportCsv() {
|
||||
const headers = {
|
||||
Date: 'date',
|
||||
Name: 'name',
|
||||
Type: 'type',
|
||||
Narration: 'narration',
|
||||
Debit: 'debit',
|
||||
Credit: 'credit',
|
||||
Running: 'running',
|
||||
Posted: 'posted'
|
||||
};
|
||||
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.data)], {type: 'text/csv;charset=utf-8;'});
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(csvData);
|
||||
link.setAttribute('download', 'voids-reprints-report.csv');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import {VoidsReprintsReportModule} from './voids-reprints-report.module';
|
||||
|
||||
describe('VoidsReprintsReportModule', () => {
|
||||
let pvoidsReprintsReportModule: VoidsReprintsReportModule;
|
||||
|
||||
beforeEach(() => {
|
||||
pvoidsReprintsReportModule = new VoidsReprintsReportModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(pvoidsReprintsReportModule).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,61 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MatNativeDateModule } from '@angular/material/core';
|
||||
import { MatDatepickerModule } from '@angular/material/datepicker';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { SharedModule} from '../shared/shared.module';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { VoidsReprintsReportRoutingModule } from './voids-reprints-report-routing.module';
|
||||
import { VoidsReprintsReportComponent } from './voids-reprints-report.component';
|
||||
import { MomentDateAdapter } from '@angular/material-moment-adapter';
|
||||
import { A11yModule } from '@angular/cdk/a11y';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
|
||||
export const MY_FORMATS = {
|
||||
parse: {
|
||||
dateInput: 'DD-MMM-YYYY',
|
||||
},
|
||||
display: {
|
||||
dateInput: 'DD-MMM-YYYY',
|
||||
monthYearLabel: 'MMM YYYY',
|
||||
dateA11yLabel: 'DD-MMM-YYYY',
|
||||
monthYearA11yLabel: 'MMM YYYY',
|
||||
},
|
||||
};
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
A11yModule,
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatAutocompleteModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatDatepickerModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatNativeDateModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
SharedModule,
|
||||
VoidsReprintsReportRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
VoidsReprintsReportComponent
|
||||
],
|
||||
providers: [
|
||||
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
|
||||
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
|
||||
]
|
||||
})
|
||||
export class VoidsReprintsReportModule {
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {VoidsReprintsReportService} from './voids-reprints-report.service';
|
||||
|
||||
describe('VoidsReprintsReportService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [VoidsReprintsReportService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([VoidsReprintsReportService], (service: VoidsReprintsReportService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -0,0 +1,36 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { VoidsReprintsReport } from './voids-reprints-report';
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
|
||||
const url = '/v1/voids-reprints-report';
|
||||
const serviceName = 'VoidsReprintsReportService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class VoidsReprintsReportService {
|
||||
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
get(startDate: string, finishDate): Observable<VoidsReprintsReport> {
|
||||
const options = {params: new HttpParams()};
|
||||
if (startDate !== null) {
|
||||
options.params = options.params.set('s', startDate);
|
||||
}
|
||||
if (finishDate !== null) {
|
||||
options.params = options.params.set('f', finishDate);
|
||||
}
|
||||
return <Observable<VoidsReprintsReport>>this.http.get<VoidsReprintsReport>(url, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'get'))
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
export class VoidsReprintsReportItem {
|
||||
date: string;
|
||||
billId: string;
|
||||
amount: number;
|
||||
settlement: string;
|
||||
}
|
||||
|
||||
export class VoidsReprintsReport {
|
||||
startDate: string;
|
||||
finishDate: string;
|
||||
amounts?: VoidsReprintsReportItem[];
|
||||
}
|
Loading…
Reference in New Issue