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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions admin/propalehistory_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
// Demander la création d'un nouvelle version à la modification d'une proposition
$formSetup->newItem('PROPALEHISTORY_ARCHIVE_ON_MODIFY')->setAsYesNo();

// new version is created with date now by default (archive button or archive on modify)
$formSetup->newItem('PROPALEHISTORY_ARCHIVE_WITH_DATE_NOW')->setAsYesNo();

$formSetup->newItem('EXPERIMENTAL_OPTIONS')->setAsTitle();

Expand Down
9 changes: 6 additions & 3 deletions class/actions_propalehistory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => (getDolGlobalInt('PROPALEHISTORY_ARCHIVE_WITH_DATE_NOW') ? dol_now() : $object->date), 'datenow' => 1),
);
$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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -236,7 +239,7 @@ function doActions($parameters, &$object, &$action, $hookmanager) {
$object->id = $_REQUEST['id'];
$object->db = $db;
} elseif($actionATM == 'createVersion') {
$result = TPropaleHist::archiverPropale($ATMdb, $object);
$result = TPropaleHist::archiverPropale($ATMdb, $object, (getDolGlobalInt('PROPALEHISTORY_ARCHIVE_WITH_DATE_NOW') ? dol_now() : ''));
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
} else {
Expand Down
26 changes: 18 additions & 8 deletions class/propaleHist.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions langs/en_US/propalehistory.lang
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ HistoryVersionSuccessfullDelete = Version was deleted successfully
HistoryVersionSuccessfullRestored = Version proposal successfully restored

PROPALEHISTORY_ARCHIVE_ON_MODIFY = Ask archiving when modifying a proposal
PROPALEHISTORY_ARCHIVE_WITH_DATE_NOW = Create a new version with the current date by default
PROPALEHISTORY_ARCHIVE_PDF_TOO = Archive the PDF too
# PROPALEHISTORY_AUTO_ARCHIVE ?
PROPALEHISTORY_AUTO_ARCHIVE_DESC = Automatically archive a sales proposal when it is validated
Expand Down
5 changes: 3 additions & 2 deletions langs/fr_FR/propalehistory.lang
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Module104090Desc = Module permettant d'historiser et de versionner les différen

AbricotNotFound = Le module complémentaire gratuit Abricot ne semble pas installé dans votre environnement mais est nécessaire pour utiliser ce module. Merci de le télécharger à l'adresse suivante

ArchiveProposal = Création une nouvelle version de la proposition
ArchiveProposalCheckboxLabel = Creer une nouvelle version la proposition ?
ArchiveProposal = Création d'une nouvelle version de la proposition
ArchiveProposalCheckboxLabel = Créer une nouvelle version de la proposition ?
AutoArchive = Archiver automatiquement une proposition commerciale lors de sa validation

ConfirmModifyProposal = Confirmer la modification de la proposition
Expand All @@ -14,6 +14,7 @@ HistoryVersionSuccessfullDelete = Version historisée supprimée avec succès
HistoryVersionSuccessfullRestored = Version de proposition restaurée avec succès

PROPALEHISTORY_ARCHIVE_ON_MODIFY = Demander la création d'un nouvelle version à la modification d'une proposition
PROPALEHISTORY_ARCHIVE_WITH_DATE_NOW = Mettre la date du jour par défaut à la création d'une nouvelle version
PROPALEHISTORY_ARCHIVE_PDF_TOO = Archiver aussi le PDF
# PROPALEHISTORY_AUTO_ARCHIVE ?
PROPALEHISTORY_AUTO_ARCHIVE_DESC = Archiver automatiquement une proposition commerciale lors de sa validation
Expand Down