add payment
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/config.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/helpers/api_helper.dart';
|
||||
import 'package:fcs/domain/entities/payment.dart';
|
||||
import 'package:fcs/helpers/firebase_helper.dart';
|
||||
import 'package:fcs/helpers/paginator.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as Path;
|
||||
|
||||
class InvoiceModel extends BaseModel {
|
||||
final log = Logger('InvoiceModel');
|
||||
@@ -135,11 +133,33 @@ class InvoiceModel extends BaseModel {
|
||||
_invoices = [];
|
||||
}
|
||||
|
||||
Future<Invoice> getInvoice(String id) async {
|
||||
String path = "/$invoices_collection";
|
||||
try {
|
||||
var ref = Firestore.instance.collection("$path").document(id);
|
||||
var snap = await ref.get(source: Source.server);
|
||||
if (snap.exists) {
|
||||
var s = Invoice.fromMap(snap.data, snap.documentID);
|
||||
return s;
|
||||
}
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> pay(Payment payment, File file) async {
|
||||
String path = Path.join(receipt_labels_files_path, user.id);
|
||||
String url = await uploadStorage(path, file);
|
||||
payment.paymentReceiptURL = url;
|
||||
return Services.instance.invoiceService.pay(payment);
|
||||
}
|
||||
|
||||
Future<void> updatePaymentStatus(Payment payment) async {
|
||||
return Services.instance.invoiceService.updatPaymentStatus(payment);
|
||||
}
|
||||
|
||||
Future<void> createInvoice(Invoice invoice) async {
|
||||
File file = await downloadPDF("invoice", invoice.toMap());
|
||||
String url = await uploadStorage("pdfs", file);
|
||||
print("uploaded url: $url");
|
||||
invoice.invoiceURL = url;
|
||||
return Services.instance.invoiceService.createInvoice(invoice);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user