Skip to content

Instantly share code, notes, and snippets.

@plusangel
Created August 29, 2019 16:09
Show Gist options
  • Select an option

  • Save plusangel/e07bb911aeffdcfb6e2fdf0458d51da7 to your computer and use it in GitHub Desktop.

Select an option

Save plusangel/e07bb911aeffdcfb6e2fdf0458d51da7 to your computer and use it in GitHub Desktop.
invoices example in modern c++
#ifndef INVOICE_H_
#define INVOICE_H_
#include <chrono>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#include "Customer.h"
#include "InvoiceLineItem.h"
#include "Money.h"
#include "UniqueIdentifier.h"
using InvoiceLineItemPtr = std::shared_ptr<InvoiceLineItem>;
using InvoiceLineItems = std::vector<InvoiceLineItemPtr>;
using InvoiceRecipient = Customer;
using InvoiceRecipientPtr = std::shared_ptr<InvoiceRecipient>;
using DateTime = std::chrono:system_clock::time_point;
class Invoice {
public:
explicit Invoice(const UniqueIdentifier& invoiceNumber);
Invoice() = delete;
void setRecipient(const InvoiceRecipientPtr& recipient);
void setDateTimeOfInvoicing(const DateTime& dateTimeOfInvoicing);
Money getSum() const;
Money getSumWithoutTax() const;
void addLineItem(const InvoiceLineItemPtr& lineItem);
private:
friend std::ostream& operator<<(std::ostream& outstream, const Invoice& invoice);
std::string getDateTimeOInvoicingAsString() const;
UniqueIdentifier invoiceNumber;
DateTime dateTimeOfInvoicing;
InvoiceRecipientPtr recipient;
InvoiceLineItems invoiceLineItems;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment