Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aspangaro committed May 23, 2019
1 parent d9e9cb2 commit 4ba8cf0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 24 deletions.
76 changes: 53 additions & 23 deletions htdocs/accountancy/bookkeeping/list.php
Expand Up @@ -32,6 +32,7 @@
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';

// Load translation files required by the page
$langs->loadLangs(array("accountancy"));
Expand Down Expand Up @@ -146,7 +147,7 @@
't.code_journal'=>array('label'=>$langs->trans("Codejournal"), 'checked'=>1),
't.date_creation'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0),
't.tms'=>array('label'=>$langs->trans("DateModification"), 'checked'=>0),
't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>0),
't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>1),
);

if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) unset($arrayfields['t.lettering_code']);
Expand Down Expand Up @@ -364,43 +365,65 @@

// Export into a file with format defined into setup (FEC, CSV, ...)
if ($action == 'export_file') {
$reexportMovements = GETPOST('already_exported')=='on'?1:0;

$result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter, 'AND', $reexportMovements);
$result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter, 'AND', $conf->global->ACCOUNTING_REEXPORT);

if ($result < 0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
// Export files
$accountancyexport = new AccountancyExport($db);
$accountancyexport->export($object->lines);

// TODO Move in class bookKeeping
// Specify as export : update field date_export
foreach ( $object->lines as $movement ) {
$now = dol_now();
$sql = " UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping";
$sql .= " SET date_export = '" . $db->idate($now) . "'";
$sql .= " WHERE rowid = " . $movement->id;

dol_syslog("/accountancy/bookeeping/list.php Function export_file Specify movements as exported sql=" . $sql, LOG_DEBUG);
if ($db->query($sql)) {
$db->commit();
} else {
$db->rollback();
if (! empty($accountancyexport->errors))
{
setEventMessages('', $accountancyexport->errors, 'errors');
} else {
// Specify as export : update field date_export
// TODO Move in class bookKeeping
$error=0;
$db->begin();

if (is_array($object->lines)) {
foreach ($object->lines as $movement) {
$now = dol_now();
$sql = " UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping";
$sql .= " SET date_export = '" . $db->idate($now) . "'";
$sql .= " WHERE rowid = " . $movement->id;

dol_syslog("/accountancy/bookeeping/list.php Function export_file Specify movements as exported sql=" . $sql, LOG_DEBUG);
$result = $db->query($sql);
if ($result) {
$db->commit();
// setEventMessages($langs->trans("AllExportedMovementsWereRecordedAsExported"), null, 'mesgs');
} else {
$db->rollback();
// setEventMessages($langs->trans("NotAllExportedMovementsCouldBeRecordedAsExported"), null, 'errors');
}
}
}
}

if (!empty($accountancyexport->errors))
{
setEventMessages('', $accountancyexport->errors, 'errors');
}
exit;
}
}

if ($action == 'setreexport') {
$export = 0;
$setreexport = GETPOST('value', 'int');
if (! dolibarr_set_const($db, "ACCOUNTING_REEXPORT", $setreexport, 'yesno', 0, '', $conf->entity)) $error++;

if (! $error) {
if ($conf->global->ACCOUNTING_REEXPORT == 1) {
setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsEnable"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsDisable"), null, 'mesgs');
}
} else {
setEventMessages($langs->trans("Error"), null, 'errors');
}
}

/*
* View
Expand Down Expand Up @@ -481,7 +504,14 @@
if (count($filter)) $buttonLabel = $langs->trans("ExportFilteredList");
else $buttonLabel = $langs->trans("ExportList");

$newcardbutton = '<input type="checkbox" name="already_exported"> ' . $langs->trans("IncludeDocsAlreadyExported");
// Button re-export
if (! empty($conf->global->ACCOUNTING_REEXPORT)) {
print $newcardbutton ='<a href="'.$_SERVER['PHP_SELF'].'?action=setreexport&value=0'.($param?'&'.$param:'').'">'.img_picto($langs->trans("Activated"), 'switch_on').'</a> ';
} else {
print $newcardbutton ='<a href="'.$_SERVER['PHP_SELF'].'?action=setreexport&value=1'.($param?'&'.$param:'').'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a> ';
}
$newcardbutton.= $langs->trans("IncludeDocsAlreadyExported");

$newcardbutton.= dolGetButtonTitle($buttonLabel, $langs->trans("ExportFilteredList").' ('.$listofformat[$conf->global->ACCOUNTING_EXPORT_MODELCSV].')', 'fa fa-file-export', $_SERVER["PHP_SELF"].'?action=export_file'.($param?'&'.$param:''));

$newcardbutton.= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-object-group', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param);
Expand Down
4 changes: 3 additions & 1 deletion htdocs/accountancy/class/bookkeeping.class.php
Expand Up @@ -936,10 +936,12 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset =
}
}
$sql.= ' WHERE t.entity IN (' . getEntity('accountancy') . ')';
if ($showAlreadyExportMovements == 0) {
$sql .= " AND t.date_export IS NULL";
}
if (count($sqlwhere) > 0) {
$sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
}

if (! empty($sortfield)) {
$sql .= $this->db->order($sortfield, $sortorder);
}
Expand Down
4 changes: 4 additions & 0 deletions htdocs/langs/en_US/main.lang
Expand Up @@ -843,6 +843,10 @@ ExportFilteredList=Export filtered list
ExportList=Export list
ExportOptions=Export Options
IncludeDocsAlreadyExported=Include docs already exported
ExportOfPiecesAlreadyExportedIsEnable=Export of pieces already exported is enable
ExportOfPiecesAlreadyExportedIsDisable=Export of pieces already exported is disable
AllExportedMovementsWereRecordedAsExported=All exported movements were recorded as exported
NotAllExportedMovementsCouldBeRecordedAsExported=Not all exported movements could be recorded as exported
Miscellaneous=Miscellaneous
Calendar=Calendar
GroupBy=Group by...
Expand Down

0 comments on commit 4ba8cf0

Please sign in to comment.