VVInvoice::addRental
The invocation of the addRental() function inserts new data into the rentals table and updates the videos table. The source code of this member function can be found in the source file invoice.cpp.
void
VVInvoice::addRental(unsigned long aVideoID) //1
{
RWDBConnection dbSession = aDB_.connection(); //2
dbSession.beginTransaction(); //3
RWDateTime rentalDate(9,6,2000); //4
// due date is three(3) days from default
RWDateTime dueDate(rentalDate); //5
dueDate = dueDate + (3 * RWDateTime::millisecsInDay); //6
// returnDate is not assigned now, so make it invalid
RWDateTime returnDate; //7
// add a rental transaction
VVRentalTransactionRepository rentals(aDB_, rentalTableName); //8
VVRentalTransaction aRental(aCustomerID_, aVideoID,
aInvoiceID_, rentalDate,
dueDate, returnDate); //9
rentals.insert(aRental, dbSession); //10
// update video inventory
VVVideoRepository videos(aDB_, videoTableName); //11
VVVideo aVideo("", aVideoID, 0, "", 0, 0, ""); //12
aVideo = videos.find(aVideo); //13
if (aVideo.numOnHand() > 0) //14
aVideo.numOnHand(aVideo.numOnHand() - 1); //15
videos.update(aVideo, aVideo, dbSession); //16
// commit the transaction
dbSession.commitTransaction(); //17
}