File indexing completed on 2024-04-28 05:08:14

0001 /***************************************************************************
0002     Copyright (C) 2005-2009 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #include "borrower.h"
0026 #include "entry.h"
0027 #include "utils/string_utils.h"
0028 
0029 using Tellico::Data::Loan;
0030 using Tellico::Data::Borrower;
0031 
0032 Loan::Loan(Tellico::Data::EntryPtr entry, QDate loanDate, QDate dueDate, const QString& note)
0033     : QSharedData(), m_uid(Tellico::uid()), m_borrower(nullptr), m_entry(entry), m_loanDate(loanDate), m_dueDate(dueDate),
0034       m_note(note), m_inCalendar(false) {
0035 }
0036 
0037 Loan::Loan(const Loan& other) : QSharedData(other), m_uid(Tellico::uid()), m_borrower(other.m_borrower),
0038       m_entry(other.m_entry), m_loanDate(other.m_loanDate), m_dueDate(other.m_dueDate),
0039       m_note(other.m_note), m_inCalendar(false) {
0040 }
0041 
0042 Tellico::Data::BorrowerPtr Loan::borrower() const {
0043   return m_borrower;
0044 }
0045 
0046 Tellico::Data::EntryPtr Loan::entry() const {
0047   return m_entry;
0048 }
0049 
0050 Borrower::Borrower(const QString& name_, const QString& uid_)
0051     : QSharedData(), m_name(name_), m_uid(uid_) {
0052 }
0053 
0054 Borrower::Borrower(const Borrower& b)
0055     : QSharedData(b), m_name(b.m_name), m_uid(b.m_uid), m_loans(b.m_loans) {
0056 }
0057 
0058 Borrower& Borrower::operator=(const Borrower& other_) {
0059   if(this == &other_) return *this;
0060 
0061 //  static_cast<QSharedData&>(*this) = static_cast<const QSharedData&>(other_);
0062   m_name = other_.m_name;
0063   m_uid = other_.m_uid;
0064   m_loans = other_.m_loans;
0065   return *this;
0066 }
0067 
0068 Tellico::Data::LoanPtr Borrower::loan(Tellico::Data::EntryPtr entry_) {
0069   foreach(LoanPtr loan, m_loans) {
0070     if(loan->entry() == entry_) {
0071       return loan;
0072     }
0073   }
0074   return LoanPtr();
0075 }
0076 
0077 void Borrower::addLoan(Tellico::Data::LoanPtr loan_) {
0078   if(loan_) {
0079     m_loans.append(loan_);
0080     loan_->setBorrower(BorrowerPtr(this));
0081   }
0082 }
0083 
0084 bool Borrower::removeLoan(Tellico::Data::LoanPtr loan_) {
0085   m_loans.removeAll(loan_);
0086   return true;
0087 }
0088 
0089 bool Borrower::hasEntry(Tellico::Data::EntryPtr entry_) {
0090   foreach(const LoanPtr loan, m_loans) {
0091     if(loan->entry() == entry_) {
0092       return true;
0093     }
0094   }
0095   return false;
0096 }