update on specifications on suggesting a booth/conf since its now two separated pages

This commit is contained in:
Dorian Vabre 2021-05-06 11:59:24 +02:00
parent df78aaff88
commit c56c7afa89
2 changed files with 42 additions and 103 deletions

View File

@ -378,7 +378,7 @@ if (empty($reshook) && $action == 'add') {
$errmsg .= $conforbooth->error; $errmsg .= $conforbooth->error;
} else { } else {
// If this is a paying booth, we have to redirect to payment page and create an invoice // If this is a paying booth, we have to redirect to payment page and create an invoice
if (GETPOST("suggestbooth") && !empty(floatval($project->price_booth))) { if (!empty(floatval($project->price_booth))) {
$productforinvoicerow = new Product($db); $productforinvoicerow = new Product($db);
$resultprod = $productforinvoicerow->fetch($conf->global->SERVICE_BOOTH_LOCATION); $resultprod = $productforinvoicerow->fetch($conf->global->SERVICE_BOOTH_LOCATION);
if ($resultprod < 0) { if ($resultprod < 0) {
@ -437,7 +437,7 @@ if (empty($reshook) && $action == 'add') {
} }
} }
} else { } else {
// If no price has been set for the booth or this is a conference, we confirm it as suggested and we update // If no price has been set for the booth, we confirm it as suggested and we update
$conforbooth->status = CONFERENCEORBOOTH::STATUS_SUGGESTED; $conforbooth->status = CONFERENCEORBOOTH::STATUS_SUGGESTED;
$conforbooth->update($user); $conforbooth->update($user);
// Sending mail // Sending mail

View File

@ -378,110 +378,49 @@ if (empty($reshook) && $action == 'add') {
$errmsg .= $conforbooth->error; $errmsg .= $conforbooth->error;
} else { } else {
// If this is a paying booth, we have to redirect to payment page and create an invoice // If this is a paying booth, we have to redirect to payment page and create an invoice
if (GETPOST("suggestbooth") && !empty(floatval($project->price_booth))) { $conforbooth->status = CONFERENCEORBOOTH::STATUS_SUGGESTED;
$productforinvoicerow = new Product($db); $conforbooth->update($user);
$resultprod = $productforinvoicerow->fetch($conf->global->SERVICE_BOOTH_LOCATION); // Sending mail
if ($resultprod < 0) { require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$error++; include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$errmsg .= $productforinvoicerow->error; $formmail = new FormMail($db);
} else { // Set output language
$facture = new Facture($db); $outputlangs = new Translate('', $conf);
$facture->type = Facture::TYPE_STANDARD; $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
$facture->socid = $thirdparty->id; // Load traductions files required by page
$facture->paye = 0; $outputlangs->loadLangs(array("main", "members"));
$facture->date = dol_now(); // Get email content from template
$facture->cond_reglement_id = $contact->cond_reglement_id; $arraydefaultmessage = null;
if (empty($facture->cond_reglement_id)) { $labeltouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT;
$paymenttermstatic = new PaymentTerm($contact->db); if (!empty($labeltouse)) {
$facture->cond_reglement_id = $paymenttermstatic->getDefaultId(); $arraydefaultmessage = $formmail->getEMailTemplate($db, 'eventorganization_send', $user, $outputlangs, $labeltouse, 1, '');
if (empty($facture->cond_reglement_id)) { }
$error++;
$contact->error = 'ErrorNoPaymentTermRECEPFound';
$contact->errors[] = $contact->error;
}
}
$resultfacture = $facture->create($user);
if ($resultfacture <= 0) {
$contact->error = $facture->error;
$contact->errors = $facture->errors;
$error++;
} else {
$facture->add_object_linked($contact->element, $contact->id);
}
}
if (!$error) { if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
// Add line to draft invoice $subject = $arraydefaultmessage->topic;
$vattouse = get_default_tva($mysoc, $thirdparty, $productforinvoicerow->id); $msg = $arraydefaultmessage->content;
$result = $facture->addline($langs->trans("BoothLocationFee", $conforbooth->label, dol_print_date($conforbooth->datep, '%d/%m/%y %H:%M:%S'), dol_print_date($conforbooth->datep2, '%d/%m/%y %H:%M:%S')), floatval($project->price_booth), 1, $vattouse, 0, 0, $productforinvoicerow->id, 0, dol_now(), '', 0, 0, '', 'HT', 0, 1); }
if ($result <= 0) {
$contact->error = $facture->error; $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
$contact->errors = $facture->errors; complete_substitutions_array($substitutionarray, $outputlangs, $object);
$error++;
} $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
if (!$error) { $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
$valid = true;
$sourcetouse = 'boothlocation'; $sendto = $thirdparty->email;
$reftouse = $facture->id; $from = $conf->global->MAILING_EMAIL_FROM;
$redirection = $dolibarr_main_url_root.'/public/payment/newpayment.php?source='.$sourcetouse.'&ref='.$reftouse.'&booth='.$conforbooth->id; $urlback = $_SERVER["REQUEST_URI"];
if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { $ishtml = dol_textishtml($texttosend); // May contain urls
$redirection .= '&securekey='.dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $sourcetouse . $reftouse, 2); // Use the source in the hash to avoid duplicates if the references are identical
} else { $mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(), '', '', 0, $ishtml);
$redirection .= '&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
} $result = $mailfile->sendfile();
} if ($result) {
Header("Location: ".$redirection); dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
exit;
}
}
} else { } else {
// If no price has been set for the booth or this is a conference, we confirm it as suggested and we update dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
$conforbooth->status = CONFERENCEORBOOTH::STATUS_SUGGESTED;
$conforbooth->update($user);
// Sending mail
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
// Set output language
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
// Load traductions files required by page
$outputlangs->loadLangs(array("main", "members"));
// Get email content from template
$arraydefaultmessage = null;
$labeltouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT;
if (!empty($labeltouse)) {
$arraydefaultmessage = $formmail->getEMailTemplate($db, 'eventorganization_send', $user, $outputlangs, $labeltouse, 1, '');
}
if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
$subject = $arraydefaultmessage->topic;
$msg = $arraydefaultmessage->content;
}
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
complete_substitutions_array($substitutionarray, $outputlangs, $object);
$subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
$texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
$sendto = $thirdparty->email;
$from = $conf->global->MAILING_EMAIL_FROM;
$urlback = $_SERVER["REQUEST_URI"];
$ishtml = dol_textishtml($texttosend); // May contain urls
$mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(), '', '', 0, $ishtml);
$result = $mailfile->sendfile();
if ($result) {
dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
} else {
dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
}
} }
} }
} }