FIX Add a test to avoid to reset binding by error.
This commit is contained in:
parent
56944115cb
commit
930512d9a2
@ -117,30 +117,6 @@ if ($action == 'validatehistory') {
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('AutomaticBindingDone'), null, 'mesgs');
|
||||
}
|
||||
} elseif ($action == 'cleanaccountancycode') {
|
||||
$error = 0;
|
||||
$db->begin();
|
||||
|
||||
// Now clean
|
||||
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
|
||||
$sql1.= " SET fk_code_ventilation = 0";
|
||||
$sql1.= " WHERE fd.fk_facture IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture as f";
|
||||
$sql1.= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'";
|
||||
$sql1.= " AND f.datef <= '" . $db->idate($search_date_end) . "'";
|
||||
$sql1.= " AND f.entity IN (" . getEntity('accountancy') . ")";
|
||||
$sql1.=")";
|
||||
|
||||
dol_syslog("htdocs/accountancy/customer/index.php cleanaccountancycode", LOG_DEBUG);
|
||||
|
||||
$resql1 = $db->query($sql1);
|
||||
if (! $resql1) {
|
||||
$error ++;
|
||||
$db->rollback();
|
||||
setEventMessage($db->lasterror(), 'errors');
|
||||
} else {
|
||||
$db->commit();
|
||||
setEventMessage($langs->trans('Done'), 'mesgs');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -183,8 +159,6 @@ print '<br>';
|
||||
$y = $year_current;
|
||||
|
||||
$buttonbind = '<a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?year=' . $year_current . '&action=validatehistory">' . $langs->trans("ValidateHistory") . '</a>';
|
||||
$buttonreset = '';
|
||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) $buttonreset = '<a class="butActionDelete" href="' . $_SERVER['PHP_SELF'] . '?year=' . $year_current . '&action=cleanaccountancycode">' . $langs->trans("CleanHistory", $year_current) . '</a>';
|
||||
|
||||
|
||||
print_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, '');
|
||||
@ -262,7 +236,7 @@ print '</div>';
|
||||
print '<br>';
|
||||
|
||||
|
||||
print_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), $buttonreset, '');
|
||||
print_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), '', '');
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
@ -110,27 +110,37 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x',
|
||||
if (is_array($changeaccount) && count($changeaccount) > 0) {
|
||||
$error = 0;
|
||||
|
||||
if (! (GETPOST('account_parent','int') >= 0))
|
||||
{
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Account")), null, 'errors');
|
||||
}
|
||||
|
||||
$db->begin();
|
||||
|
||||
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as l";
|
||||
$sql1 .= " SET l.fk_code_ventilation=" . GETPOST('account_parent','int');
|
||||
$sql1 .= ' WHERE l.rowid IN (' . implode(',', $changeaccount) . ')';
|
||||
if (! $error)
|
||||
{
|
||||
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as l";
|
||||
$sql1 .= " SET l.fk_code_ventilation=" . (GETPOST('account_parent','int') > 0 ? GETPOST('account_parent','int') : '0');
|
||||
$sql1 .= ' WHERE l.rowid IN (' . implode(',', $changeaccount) . ')';
|
||||
|
||||
dol_syslog('accountancy/customer/lines.php::changeaccount sql= ' . $sql1);
|
||||
$resql1 = $db->query($sql1);
|
||||
if (! $resql1) {
|
||||
$error ++;
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
if (! $error) {
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('Save'), null, 'mesgs');
|
||||
} else {
|
||||
$db->rollback();
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
dol_syslog('accountancy/customer/lines.php::changeaccount sql= ' . $sql1);
|
||||
$resql1 = $db->query($sql1);
|
||||
if (! $resql1) {
|
||||
$error ++;
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
if (! $error) {
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('Save'), null, 'mesgs');
|
||||
} else {
|
||||
$db->rollback();
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
|
||||
$account_parent = ''; // Protection to avoid to mass apply it a second time
|
||||
}
|
||||
|
||||
$account_parent = ''; // Protection to avoid to mass apply it a second time
|
||||
}
|
||||
|
||||
|
||||
@ -272,7 +282,7 @@ if ($result) {
|
||||
print $langs->trans("DescVentilDoneCustomer") . '<br>';
|
||||
|
||||
print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
|
||||
print $formaccounting->select_account($account_parent, 'account_parent', 1);
|
||||
print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle');
|
||||
print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '"/></div>';
|
||||
|
||||
$moreforfilter = '';
|
||||
|
||||
@ -114,30 +114,6 @@ if ($action == 'validatehistory') {
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('AutomaticBindingDone'), null, 'mesgs');
|
||||
}
|
||||
} elseif ($action == 'cleanaccountancycode') {
|
||||
$error = 0;
|
||||
$db->begin();
|
||||
|
||||
// Now clean
|
||||
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd";
|
||||
$sql1.= " SET fk_code_ventilation = 0";
|
||||
$sql1.= " WHERE erd.fk_expensereport IN ( SELECT er.rowid FROM " . MAIN_DB_PREFIX . "expensereport as er";
|
||||
$sql1.= " WHERE er.date_debut >= '" . $db->idate($search_date_start) . "'";
|
||||
$sql1.= " AND er.date_debut <= '" . $db->idate($search_date_end) . "'";
|
||||
$sql1.= " AND er.entity IN (" . getEntity('accountancy') . ")";
|
||||
$sql1.=")";
|
||||
|
||||
dol_syslog("htdocs/accountancy/customer/index.php cleanaccountancycode", LOG_DEBUG);
|
||||
|
||||
$resql1 = $db->query($sql1);
|
||||
if (! $resql1) {
|
||||
$error ++;
|
||||
$db->rollback();
|
||||
setEventMessage($db->lasterror(), 'errors');
|
||||
} else {
|
||||
$db->commit();
|
||||
setEventMessage($langs->trans('Done'), 'mesgs');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -180,8 +156,6 @@ print '<br>';
|
||||
$y = $year_current;
|
||||
|
||||
$buttonbind = '<a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?year=' . $year_current . '&action=validatehistory">' . $langs->trans("ValidateHistory") . '</a>';
|
||||
$buttonreset = '';
|
||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) $buttonreset = '<a class="butActionDelete" href="' . $_SERVER['PHP_SELF'] . '?year=' . $year_current . '&action=cleanaccountancycode">' . $langs->trans("CleanHistory", $year_current) . '</a>';
|
||||
|
||||
|
||||
print_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, '');
|
||||
@ -253,7 +227,7 @@ print '</div>';
|
||||
|
||||
print '<br>';
|
||||
|
||||
print_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), $buttonreset, '');
|
||||
print_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), '', '');
|
||||
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
|
||||
@ -43,7 +43,7 @@ $langs->load("accountancy");
|
||||
$langs->load("trips");
|
||||
$langs->load("productbatch");
|
||||
|
||||
$account_parent = GETPOST('account_parent');
|
||||
$account_parent = GETPOST('account_parent','int');
|
||||
$changeaccount = GETPOST('changeaccount');
|
||||
// Search Getpost
|
||||
$search_expensereport = GETPOST('search_expensereport', 'alpha');
|
||||
@ -103,27 +103,36 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x',
|
||||
if (is_array($changeaccount) && count($changeaccount) > 0) {
|
||||
$error = 0;
|
||||
|
||||
if (! (GETPOST('account_parent','int') >= 0))
|
||||
{
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Account")), null, 'errors');
|
||||
}
|
||||
|
||||
$db->begin();
|
||||
|
||||
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd";
|
||||
$sql1 .= " SET erd.fk_code_ventilation=" . GETPOST('account_parent','int');
|
||||
$sql1 .= ' WHERE erd.rowid IN (' . implode(',', $changeaccount) . ')';
|
||||
if (! $error)
|
||||
{
|
||||
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd";
|
||||
$sql1 .= " SET erd.fk_code_ventilation=" . (GETPOST('account_parent','int') > 0 ? GETPOST('account_parent','int') : '0');
|
||||
$sql1 .= ' WHERE erd.rowid IN (' . implode(',', $changeaccount) . ')';
|
||||
|
||||
dol_syslog('accountancy/expensereport/lines.php::changeaccount sql= ' . $sql1);
|
||||
$resql1 = $db->query($sql1);
|
||||
if (! $resql1) {
|
||||
$error ++;
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
if (! $error) {
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('Save'), null, 'mesgs');
|
||||
} else {
|
||||
$db->rollback();
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
dol_syslog('accountancy/expensereport/lines.php::changeaccount sql= ' . $sql1);
|
||||
$resql1 = $db->query($sql1);
|
||||
if (! $resql1) {
|
||||
$error ++;
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
if (! $error) {
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('Save'), null, 'mesgs');
|
||||
} else {
|
||||
$db->rollback();
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
|
||||
$account_parent = ''; // Protection to avoid to mass apply it a second time
|
||||
$account_parent = ''; // Protection to avoid to mass apply it a second time
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -246,7 +255,7 @@ if ($result) {
|
||||
print $langs->trans("DescVentilDoneExpenseReport") . '<br>';
|
||||
|
||||
print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
|
||||
print $formaccounting->select_account(GETPOST('account_parent'), 'account_parent', 1);
|
||||
print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle');
|
||||
print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '" /></div>';
|
||||
|
||||
$moreforfilter = '';
|
||||
|
||||
@ -115,31 +115,9 @@ if ($action == 'validatehistory') {
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('AutomaticBindingDone'), null, 'mesgs');
|
||||
}
|
||||
} elseif ($action == 'cleanaccountancycode') {
|
||||
$error = 0;
|
||||
$db->begin();
|
||||
|
||||
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd";
|
||||
$sql1.= " SET fk_code_ventilation = 0";
|
||||
$sql1.= " WHERE fd.fk_facture_fourn IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
|
||||
$sql1.= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'";
|
||||
$sql1.= " AND f.datef <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "'";
|
||||
$sql1.= " AND f.entity IN (" . getEntity('accountancy') . ")";
|
||||
$sql1.= ")";
|
||||
|
||||
dol_syslog("htdocs/accountancy/customer/index.php cleanaccountancycode", LOG_DEBUG);
|
||||
|
||||
$resql1 = $db->query($sql1);
|
||||
if (! $resql1) {
|
||||
$error ++;
|
||||
$db->rollback();
|
||||
setEventMessage($db->lasterror(), 'errors');
|
||||
} else {
|
||||
$db->commit();
|
||||
setEventMessage($langs->trans('Done'), 'mesgs');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
@ -178,8 +156,6 @@ print '<br>';
|
||||
$y = $year_current;
|
||||
|
||||
$buttonbind = '<a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?year=' . $year_current . '&action=validatehistory">' . $langs->trans("ValidateHistory") . '</a>';
|
||||
$buttonreset = '';
|
||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) $buttonreset = '<a class="butActionDelete" href="' . $_SERVER['PHP_SELF'] . '?year=' . $year_current . '&action=cleanaccountancycode">' . $langs->trans("CleanHistory", $year_current) . '</a>';
|
||||
|
||||
|
||||
print_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, '');
|
||||
@ -252,7 +228,7 @@ print '</div>';
|
||||
print '<br>';
|
||||
|
||||
|
||||
print_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), $buttonreset, '');
|
||||
print_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), '', '');
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
@ -111,27 +111,36 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x',
|
||||
if (is_array($changeaccount) && count($changeaccount) > 0) {
|
||||
$error = 0;
|
||||
|
||||
if (! (GETPOST('account_parent','int') >= 0))
|
||||
{
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Account")), null, 'errors');
|
||||
}
|
||||
|
||||
$db->begin();
|
||||
|
||||
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as l";
|
||||
$sql1 .= " SET l.fk_code_ventilation=" . GETPOST('account_parent','int');
|
||||
$sql1 .= ' WHERE l.rowid IN (' . implode(',', $changeaccount) . ')';
|
||||
if (! $error)
|
||||
{
|
||||
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as l";
|
||||
$sql1 .= " SET l.fk_code_ventilation=" . (GETPOST('account_parent','int') > 0 ? GETPOST('account_parent','int') : '0');
|
||||
$sql1 .= ' WHERE l.rowid IN (' . implode(',', $changeaccount) . ')';
|
||||
|
||||
dol_syslog('accountancy/supplier/lines.php::changeaccount sql= ' . $sql1);
|
||||
$resql1 = $db->query($sql1);
|
||||
if (! $resql1) {
|
||||
$error ++;
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
if (! $error) {
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('Save'), null, 'mesgs');
|
||||
} else {
|
||||
$db->rollback();
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
dol_syslog('accountancy/supplier/lines.php::changeaccount sql= ' . $sql1);
|
||||
$resql1 = $db->query($sql1);
|
||||
if (! $resql1) {
|
||||
$error ++;
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
if (! $error) {
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans('Save'), null, 'mesgs');
|
||||
} else {
|
||||
$db->rollback();
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
|
||||
$account_parent = ''; // Protection to avoid to mass apply it a second time
|
||||
$account_parent = ''; // Protection to avoid to mass apply it a second time
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -269,7 +278,7 @@ if ($result) {
|
||||
print $langs->trans("DescVentilDoneSupplier") . '<br>';
|
||||
|
||||
print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
|
||||
print $formaccounting->select_account($account_parent, 'account_parent', 1);
|
||||
print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle');
|
||||
print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '" /></div>';
|
||||
|
||||
$moreforfilter = '';
|
||||
|
||||
@ -243,7 +243,7 @@ class FormAccounting extends Form
|
||||
*
|
||||
* @param string $selectid Preselected id or code of accounting accounts (depends on $select_in)
|
||||
* @param string $htmlname Name of HTML field id. If name start with '.', it is name of HTML css class, so several component with same name in different forms can be used.
|
||||
* @param int $showempty Add an empty field
|
||||
* @param int $showempty 1=Add an empty field, 2=Add an empty field+'None' field
|
||||
* @param array $event Event options
|
||||
* @param int $select_in 0=selectid value is a aa.rowid (default) or 1=selectid is aa.account_number
|
||||
* @param int $select_out Set value returned by select. 0=rowid (default), 1=account_number
|
||||
@ -253,7 +253,7 @@ class FormAccounting extends Form
|
||||
*/
|
||||
function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='')
|
||||
{
|
||||
global $conf;
|
||||
global $conf, $langs;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
|
||||
|
||||
@ -318,7 +318,12 @@ class FormAccounting extends Form
|
||||
}
|
||||
}
|
||||
|
||||
$out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
|
||||
if ($showempty == 2)
|
||||
{
|
||||
$options['0'] = $langs->trans("None");
|
||||
}
|
||||
|
||||
$out .= Form::selectarray($htmlname, $options, $selected, ($showempty > 0 ? 1 : 0), 0, 0, '', 0, 0, 0, '', $morecss, 1);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user