Fix feature to close record in accounting
This commit is contained in:
parent
0fe1634f29
commit
5fed6de5b8
@ -1013,7 +1013,7 @@ class BookKeeping extends CommonObject
|
|||||||
} elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') {
|
} elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') {
|
||||||
$sqlwhere[] = $key.'\''.$this->db->escape($value).'\'';
|
$sqlwhere[] = $key.'\''.$this->db->escape($value).'\'';
|
||||||
} elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') {
|
} elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') {
|
||||||
$sqlwhere[] = $key.'='.$value;
|
$sqlwhere[] = $key.'='.((int) $value);
|
||||||
} elseif ($key == 't.subledger_account' || $key == 't.numero_compte') {
|
} elseif ($key == 't.subledger_account' || $key == 't.numero_compte') {
|
||||||
$sqlwhere[] = $key.' LIKE \''.$this->db->escape($value).'%\'';
|
$sqlwhere[] = $key.' LIKE \''.$this->db->escape($value).'%\'';
|
||||||
} elseif ($key == 't.date_creation>=' || $key == 't.date_creation<=') {
|
} elseif ($key == 't.date_creation>=' || $key == 't.date_creation<=') {
|
||||||
|
|||||||
@ -31,7 +31,8 @@ require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
|
|||||||
// Load translation files required by the page
|
// Load translation files required by the page
|
||||||
$langs->loadLangs(array("compta", "bills", "other", "accountancy"));
|
$langs->loadLangs(array("compta", "bills", "other", "accountancy"));
|
||||||
|
|
||||||
$socid = GETPOST('socid', 'int');
|
$validatemonth = GETPOST('validatemonth', 'int');
|
||||||
|
$validateyear = GETPOST('validateyear', 'int');
|
||||||
|
|
||||||
$action = GETPOST('action', 'aZ09');
|
$action = GETPOST('action', 'aZ09');
|
||||||
|
|
||||||
@ -68,52 +69,47 @@ if (empty($user->rights->accounting->fiscalyear->write)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$now = dol_now();
|
||||||
|
|
||||||
if ($action == 'validate_movements_confirm' && !empty($user->rights->accounting->fiscalyear->write)) {
|
if ($action == 'validate_movements_confirm' && !empty($user->rights->accounting->fiscalyear->write)) {
|
||||||
$result = $object->fetchAll();
|
|
||||||
|
|
||||||
if ($result < 0) {
|
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
|
||||||
} else {
|
|
||||||
// Specify as export : update field date_validated on selected month/year
|
|
||||||
$error = 0;
|
|
||||||
$db->begin();
|
|
||||||
|
|
||||||
$date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
|
$date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
|
||||||
$date_end = dol_mktime(23, 59, 59, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));
|
$date_end = dol_mktime(23, 59, 59, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));
|
||||||
|
|
||||||
if (is_array($object->lines)) {
|
$error = 0;
|
||||||
foreach ($object->lines as $movement) {
|
|
||||||
$now = dol_now();
|
|
||||||
|
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
|
// Specify as export : update field date_validated on selected month/year
|
||||||
$sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping";
|
$sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping";
|
||||||
$sql .= " SET date_validated = '".$db->idate($now)."'";
|
$sql .= " SET date_validated = '".$db->idate($now)."'";
|
||||||
$sql .= " WHERE rowid = ".((int) $movement->id);
|
$sql .= " WHERE entity = " . ((int) $conf->entity);
|
||||||
$sql .= " AND doc_date >= '" . $db->idate($date_start) . "'";
|
$sql .= " AND doc_date >= '" . $db->idate($date_start) . "'";
|
||||||
$sql .= " AND doc_date <= '" . $db->idate($date_end) . "'";
|
$sql .= " AND doc_date <= '" . $db->idate($date_end) . "'";
|
||||||
|
$sql .= " AND date_validated IS NULL";
|
||||||
|
|
||||||
dol_syslog("/accountancy/closure/index.php :: Function validate_movement_confirm Specify movements as validated", LOG_DEBUG);
|
dol_syslog("/accountancy/closure/index.php action=validate_movement_confirm -> Set movements as validated", LOG_DEBUG);
|
||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
$error++;
|
$error++;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$db->commit();
|
$db->commit();
|
||||||
|
|
||||||
setEventMessages($langs->trans("AllMovementsWereRecordedAsValidated"), null, 'mesgs');
|
setEventMessages($langs->trans("AllMovementsWereRecordedAsValidated"), null, 'mesgs');
|
||||||
} else {
|
|
||||||
$error++;
|
|
||||||
$db->rollback();
|
|
||||||
setEventMessages($langs->trans("NotAllMovementsCouldBeRecordedAsValidated"), null, 'errors');
|
|
||||||
}
|
|
||||||
header("Location: ".$_SERVER['PHP_SELF']."?year=".$year_start);
|
header("Location: ".$_SERVER['PHP_SELF']."?year=".$year_start);
|
||||||
exit;
|
exit;
|
||||||
|
} else {
|
||||||
|
$db->rollback();
|
||||||
|
|
||||||
|
setEventMessages($langs->trans("NotAllMovementsCouldBeRecordedAsValidated"), null, 'errors');
|
||||||
|
$action = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user