void MainWindow::on_label_remindCustomers_linkActivated(const QString &)
{
    unpaidJobsReminderClicked = true;
    ui->label_remindCustomers->setHidden(true);

    Setting subject = SettingController::getSetting(SettingForm::keyReminderSubject),
            body = SettingController::getSetting(SettingForm::keyReminderBody);

    if (strlen(SettingController::getSetting(SettingForm::keyEmailHost).getValue()) == 0)
    { // If no email host is specified, use a mailto link to open the user's email client
        for (unsigned i = 0; i < unpaidJobs->size(); ++i)
        {
            Customer customer = CustomerController::getCustomer(unpaidJobs->at(i).getCustomerId());

            QString mailtoLink
                    = QString("mailto:") + customer.getEmailAddress()
                    + "?subject=" + subject.getValue()
                    + "&body=" + body.getValue();

            QDesktopServices::openUrl(QUrl(mailtoLink));
        }
    }
    else
    {
        for (unsigned i = 0; i < unpaidJobs->size(); ++i)
        {
            Customer customer = CustomerController::getCustomer(unpaidJobs->at(i).getCustomerId());
            EmailerThread::enqueueEmail(EmailDetails(customer.getEmailAddress(), subject.getValue(), body.getValue()));
        }
    }
}
예제 #2
0
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);
}