void JobShow::generateReceipt()
{
    Date jobDate(job.getDate());
    QString saveFolder
            = SettingForm::getPdfDirectoryWithoutSlash() + "/receipts/"
            + QDate::longMonthName(Date(job.getDate()).month) + '_' + toString(jobDate.year).c_str();

    if (!QDir(saveFolder).exists()) QDir().mkpath(saveFolder);

    Customer customer = CustomerController::getCustomer(job.getCustomerId());
    customerEmailAddress = customer.getEmailAddress();

    receiptFileName.clear();
    receiptFileName.reserve(256);
    receiptFileName += "receipt_";
    receiptFileName += customer.getForename();
    receiptFileName += customer.getSurname();
    receiptFileName += "_";
    receiptFileName += toString(job.getId());
    receiptFileName += "_";
    receiptFileName += (string)Date(job.getDate());
    receiptFileName += ".pdf";
    replaceChars(receiptFileName, ' ', '_');
    replaceChars(receiptFileName, '/', '-');
    replaceChars(receiptFileName, ':', '-');

    receiptFileName = saveFolder.toStdString() + '/' + receiptFileName;

    PdfGenerator::generateReceipt(receiptFileName.c_str(), job);
}
void TCustomer::testSurname () {
    Customer c;

    c.setSurname (tSurname);

    QVERIFY (c.getSurname () == tSurname);
}
void MainWindow::on_FindCustomer_clicked()
{
    if("" == ui->FindID->text())
    {
        QMessageBox::about(0,Title,NoCustomerID);
        ui->FindID->setFocus();
    }
    else
    {
        Customer customer;

        customer = CM.fetchCustomer(ui->FindID->text());
        if(customer.getName()!="")
        {
            ui->FindName->setText(customer.getName());
            ui->FindSurname->setText(customer.getSurname());
            ui->FindGroupID->setText(QString("%1").arg(customer.getGroupId()));
         }
        else
        {
          QMessageBox::about(0,Title,NoCustomerID);
        }
        ui->FindName->setFocus();
    }

}
void TCustomer::testConstructor () {
    Customer c (tId, tName, tSurname, tGroup);

    QVERIFY (c.getId ()      == tId      &&
             c.getName ()    == tName    &&
             c.getSurname () == tSurname &&
             c.getGroupId () == tGroup);
}
void JobShow::updateView()
{
    TaskController::sortTasksByDate(tasks);

    setWindowTitle(QString("Job for ") + Date(job.getDate()).toQStringWithoutTime());
    ui->label_dateE->setText(Date(job.getDate()));

    Customer customer = CustomerController::getCustomer(job.getCustomerId());
    ui->label_customerNameE->setText(createFullName(customer.getForename(), customer.getSurname()));

    ui->plainTextEdit_descriptionE->setPlainText(job.getDescription());

    ui->listWidget_partsE->clear();
    char partString[64];
    for (unsigned i = 0; i < parts.size(); ++i)
    {
        strcpy(partString, toString(parts[i].getQuantity()).c_str());
        strcat(partString, "x ");
        strcat(partString, parts[i].getName());
        ui->listWidget_partsE->addItem(partString);
    }

    ui->listWidget_tasksE->clear();
    for (unsigned i = 0; i < tasks.size(); ++i)
        ui->listWidget_tasksE->addItem(limitLength(tasks[i].getDescription(), 40));

    updateCharges();

    QString str;
    switch (job.getCompletionState())
    {
    case Job::NOT_DONE:    str = "Not done"; break;
    case Job::DONE_UNPAID: str = "Done - not paid"; break;
    case Job::DONE_PAID:   str = "Done - paid"; break;
    }
    ui->label_completionStateE->setText(str);

    ui->gridWidget_sendInvoiceMarkAsPaid->setHidden(job.getCompletionState() != Job::DONE_UNPAID);
    ui->pushButton_markAsDone->setHidden(job.getCompletionState() != Job::NOT_DONE);
    ui->gridWidget_paidBy->setHidden(job.getCompletionState() != Job::DONE_PAID);

    switch (job.getPaymentMethod())
    {
    case Job::NA:            str = "N/A"; break;
    case Job::CASH:          str = "Cash"; break;
    case Job::CHEQUE:        str = "Cheque"; break;
    case Job::CREDIT:        str = "Credit"; break;
    case Job::DEBIT:         str = "Debit"; break;
    case Job::BANK_TRANSFER: str = "Bank transfer"; break;
    }
    ui->label_paymentTypeE->setText(str);
    ui->label_paymentDateE->setText(Date(job.getPaymentDate()));
}
void MainWindow::updateListWidgets()
{
    const Date date(ui->calendar->selectedDate());
    ui->label_selectedDate1->setText(date.toQStringWithoutTime());
    ui->label_selectedDate2->setText(date.toQStringWithoutTime());

    ui->listWidget_jobs->clear();
    ui->listWidget_tasks->clear();

    Customer customer;
    for (unsigned i = 0; i < jobs->size(); ++i)
    {
        customer = CustomerController::getCustomer(jobs->at(i).getCustomerId());
        ui->listWidget_jobs->addItem(createFullName(customer.getForename(), customer.getSurname()));
    }

    for (unsigned i = 0; i < tasks->size(); ++i)
        ui->listWidget_tasks->addItem(limitLength(tasks->at(i).getDescription(), 30));
}