Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW select proposal date with date now by default on form confirm #73

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
NEW select proposal date with date now by default on form confirm
lvessiller-opendsi committed Sep 24, 2024
commit 6daaffd19d05c29f66ef4f3359d5b849a61d2d75
7 changes: 5 additions & 2 deletions class/actions_propalehistory.class.php
Original file line number Diff line number Diff line change
@@ -149,8 +149,9 @@ function formConfirm($parameters, &$object, &$action, $hookmanager)
if ( array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'modif') {
$formquestion = array(
array('type' => 'checkbox', 'name' => 'archive_proposal', 'label' => $langs->trans("ArchiveProposalCheckboxLabel"), 'value' => 1),
array('type' => 'date', 'name' => 'archive_proposal_date_', 'label' => $langs->trans("DatePropal"), 'value' => dol_now()),
);
$form = new Form($this->db);
$form = new Form($db);
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ArchiveProposal'), $langs->trans('ConfirmModifyProposal', $object->ref), 'propalhistory_confirm_modify', $formquestion, 'yes', 1);

$this->results = array();
@@ -193,10 +194,12 @@ function doActions($parameters, &$object, &$action, $hookmanager) {
// New version if wanted
$archive_proposal = GETPOST('archive_proposal', 'alpha');
if ($archive_proposal == 'on') {
$proposalDate = dol_mktime(0, 0, 0, GETPOST('archive_proposal_date_month', 'int'), GETPOST('archive_proposal_date_day', 'int'), GETPOST('archive_proposal_date_year', 'int'));

// hack pour stocker la bonne ref pour pouvoir la remettre avant le bloc showdocuments
$object->ref_old = $object->ref;

$result = TPropaleHist::archiverPropale($ATMdb, $object);
$result = TPropaleHist::archiverPropale($ATMdb, $object, $proposalDate);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id);
26 changes: 18 additions & 8 deletions class/propaleHist.class.php
Original file line number Diff line number Diff line change
@@ -55,11 +55,12 @@ function getObject() {
/**
* Archive proposal
*
* @param TPDOdb $PDOdb PDO connection
* @param Propal $object Proposal object
* @param TPDOdb $PDOdb PDO connection
* @param Propal $object Proposal object
* @param int|string $inputDate [=''] Proposal date from input converted to timestamp
* @return int <0 if KO, >0 if OK
*/
static function archiverPropale(&$PDOdb, &$object)
static function archiverPropale(&$PDOdb, &$object, $inputDate = '')
{
global $conf, $db, $langs;

@@ -96,15 +97,24 @@ static function archiverPropale(&$PDOdb, &$object)

$newVersionPropale->save($PDOdb);

if (getDolGlobalString('PROPALEHISTORY_ARCHIVE_AND_RESET_DATES') && $object->id > 0) {
$now = dol_now();
$fin_validite = $now + ($object->duree_validite * 24 * 3600);
if ((getDolGlobalString('PROPALEHISTORY_ARCHIVE_AND_RESET_DATES') || is_numeric($inputDate)) && $object->id > 0) {
// set proposal date and compute end validity date
if (is_numeric($inputDate)) {
$object->date = $inputDate;
} else {
$object->date = dol_now();
}
$object->datep = $object->date; // keep compatibility
$object->fin_validite = $object->date;
if (is_numeric($object->duree_validite)) {
$object->fin_validite += $object->duree_validite * 24 * 3600;
}

$db->begin();

$sql = "UPDATE " . MAIN_DB_PREFIX . "propal";
$sql .= " SET datep = '" . $db->idate($now) . "'";
$sql .= ", fin_validite = '" . $db->idate($fin_validite) . "'";
$sql .= " SET datep = '" . $db->idate($object->date) . "'";
$sql .= ", fin_validite = '" . $db->idate($object->fin_validite) . "'";
$sql .= " WHERE rowid = " . $object->id;

dol_syslog(__METHOD__, LOG_DEBUG);