Skip to content

Commit

Permalink
feat: can edit and delete billings #298
Browse files Browse the repository at this point in the history
  • Loading branch information
bvlourenco committed Dec 28, 2022
1 parent 30305de commit 88f998c
Show file tree
Hide file tree
Showing 10 changed files with 464 additions and 45 deletions.
28 changes: 11 additions & 17 deletions backend/src/mongodb/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,27 +230,21 @@ func (b *BillingsType) UpdateBilling(id primitive.ObjectID, data CreateBillingDa
var updateQuery = bson.M{
"$set": bson.M{
"status": bson.M{
"invoice": data.Status.Invoice,
"paid": data.Status.Paid,
"proForma": data.Status.ProForma,
"receipt": data.Status.Receipt,
"invoice": *data.Status.Invoice,
"paid": *data.Status.Paid,
"proForma": *data.Status.ProForma,
"receipt": *data.Status.Receipt,
},
"event": data.Event,
"value": data.Value,
"invoiceNumber": data.InvoiceNumber,
"emission": data.Emission,
"notes": data.Notes,
"event": *data.Event,
"value": *data.Value,
"invoiceNumber": *data.InvoiceNumber,
"emission": *data.Emission,
"notes": *data.Notes,
"company": *data.Company,
"visible": *data.Visible,
},
}

if data.Company != nil {
updateQuery["company"] = *data.Company
}

if data.Visible != nil {
updateQuery["visible"] = *data.Visible
}

var optionsQuery = options.FindOneAndUpdate()
optionsQuery.SetReturnDocument(options.After)

Expand Down
14 changes: 5 additions & 9 deletions backend/src/mongodb/company.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,23 +1184,19 @@ func (c *CompaniesType) UpdateBilling(companyID primitive.ObjectID, billingID pr
}

// RemoveCompanyParticipationBilling removes a billing on the company participation.
func (c *CompaniesType) RemoveCompanyParticipationBilling(companyID primitive.ObjectID) (*models.Company, error) {
func (c *CompaniesType) RemoveCompanyParticipationBilling(companyID primitive.ObjectID, event int) (*models.Company, error) {
ctx := context.Background()

var updatedCompany models.Company

currentEvent, err := Events.GetCurrentEvent()
if err != nil {
return nil, err
}

var updateQuery = bson.M{
"$pull": bson.M{
"participations.billing": "",
"$unset": bson.M{
"participations.$.billing": "",
"participations.billing": "",
},
}

var filterQuery = bson.M{"_id": companyID, "participations.event": currentEvent.ID}
var filterQuery = bson.M{"_id": companyID, "participations.event": event}

var optionsQuery = options.FindOneAndUpdate()
optionsQuery.SetReturnDocument(options.After)
Expand Down
8 changes: 4 additions & 4 deletions backend/src/router/company.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,14 @@ func deleteCompanyThread(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Could not parse credentials", http.StatusBadRequest)
return
}

company, err := mongodb.Companies.DeleteCompanyThread(id, threadID)
if err != nil {
http.Error(w, "Company or thread not found", http.StatusNotFound)
return
}
// Delete thread and posts (comments) associated to it - only if

// Delete thread and posts (comments) associated to it - only if
// thread was deleted sucessfully from speaker participation
if _, err := mongodb.Threads.DeleteThread(threadID); err != nil {
http.Error(w, "Thread not found", http.StatusNotFound)
Expand Down Expand Up @@ -598,7 +598,7 @@ func deleteCompanyParticipationBilling(w http.ResponseWriter, r *http.Request) {

backupBilling, _ := mongodb.Billings.GetBilling(billingID)

updatedCompany, err := mongodb.Companies.RemoveCompanyParticipationBilling(companyID)
updatedCompany, err := mongodb.Companies.RemoveCompanyParticipationBilling(companyID, backupBilling.Event)
if err != nil {
http.Error(w, "Could not remove billing from company participation", http.StatusExpectationFailed)
return
Expand Down
13 changes: 8 additions & 5 deletions frontend/lib/routes/company/CompanyScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,14 @@ class _CompanyScreenState extends State<CompanyScreen>
company: widget.company,
),
BillingScreen(
participations: widget.company.participations,
billingInfo: widget.company.billingInfo,
id: widget.company.id,
small: small,
),
participations: widget.company.participations,
billingInfo: widget.company.billingInfo,
id: widget.company.id,
small: small,
onBillingDeleted: (billingId) =>
companyChangedCallback(context,
fs: _companyService.deleteBilling(
widget.company.id, billingId))),
ParticipationList(
company: widget.company,
onParticipationChanged:
Expand Down
5 changes: 4 additions & 1 deletion frontend/lib/routes/company/billing/AddBillingForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class _AddBillingFormState extends State<AddBillingForm> {

void _checkBillingEvent() async {
int event = int.parse(_eventController.text);
int currentEvent = Provider.of<EventNotifier>(context, listen: false).event.id;
int currentEvent =
Provider.of<EventNotifier>(context, listen: false).event.id;
if (event != currentEvent) {
showDialog(
context: context,
Expand All @@ -87,6 +88,8 @@ class _AddBillingFormState extends State<AddBillingForm> {
});
},
);
} else {
_submit();
}
}

Expand Down
45 changes: 42 additions & 3 deletions frontend/lib/routes/company/billing/BillingCard.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import 'package:flutter/material.dart';
import 'package:frontend/components/blurryDialog.dart';
import 'package:frontend/models/billing.dart';
import 'package:frontend/routes/company/billing/editBillingForm.dart';
import 'package:intl/intl.dart';

class BillingCard extends StatefulWidget {
Billing billing;
final String id;
final bool small;
final void Function(String) onDelete;

BillingCard(
{Key? key, required this.billing, required this.id, required this.small})
{Key? key,
required this.billing,
required this.id,
required this.small,
required this.onDelete})
: super(key: key);

@override
Expand All @@ -19,6 +27,37 @@ class _BillingCardState extends State<BillingCard>
@override
bool get wantKeepAlive => true;

void _editBillingModal(context) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) {
return FractionallySizedBox(
heightFactor: 0.7,
child: Container(
child: EditBillingForm(
billing: widget.billing,
onBillingEdit: (context, _billing) {
billingChangedCallback(context, billing: _billing);
}),
));
},
);
}

void _deleteBillingDialog(context) {
showDialog(
context: context,
builder: (BuildContext context) {
return BlurryDialog('Warning',
'Are you sure you want to delete SINFO ${widget.billing.event} billing?',
() {
widget.onDelete(widget.billing.id);
});
},
);
}

Future<void> billingChangedCallback(BuildContext context,
{Billing? billing}) async {
setState(() {
Expand Down Expand Up @@ -63,7 +102,7 @@ class _BillingCardState extends State<BillingCard>
padding: const EdgeInsets.all(8.0),
child: IconButton(
onPressed: () {
// _editFlightModal(context);
_editBillingModal(context);
},
color: const Color(0xff5c7ff2),
icon: Icon(Icons.edit)),
Expand All @@ -72,7 +111,7 @@ class _BillingCardState extends State<BillingCard>
padding: const EdgeInsets.all(8.0),
child: IconButton(
onPressed: () {
// _deleteFlightDialog(context);
_deleteBillingDialog(context);
},
color: Colors.red,
icon: Icon(Icons.delete)),
Expand Down
7 changes: 5 additions & 2 deletions frontend/lib/routes/company/billing/BillingScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ class BillingScreen extends StatefulWidget {
final List<CompanyParticipation>? participations;
final String id;
final bool small;
final void Function(String) onBillingDeleted;
CompanyBillingInfo? billingInfo;

BillingScreen(
{Key? key,
this.billingInfo,
required this.participations,
required this.small,
required this.id})
required this.id,
required this.onBillingDeleted})
: super(key: key);

@override
Expand Down Expand Up @@ -136,7 +138,8 @@ class _BillingScreenState extends State<BillingScreen>
(participation) => ParticipationBillingWidget(
participation: participation,
id: widget.id,
small: widget.small),
small: widget.small,
onDelete: widget.onBillingDeleted),
)
.toList()),
);
Expand Down
Loading

0 comments on commit 88f998c

Please sign in to comment.