diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index 78f29e97595..582e54442a5 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -70,6 +70,13 @@ $pagenext = $page + 1; if ($sortorder == "") $sortorder = "ASC"; if ($sortfield == "") $sortfield = "t.doc_date,t.rowid"; +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$object = new BookKeeping($db); +$hookmanager->initHooks(array('bookkeepingbyaccountlist')); + +$formaccounting = new FormAccounting($db); +$form = new Form($db); + if (empty($search_date_start) && empty($search_date_end) && GETPOSTISSET('search_date_startday') && GETPOSTISSET('search_date_startmonth') && GETPOSTISSET('search_date_starthour')) { $sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear "; $sql .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'"; @@ -96,87 +103,112 @@ if (empty($search_date_start) && empty($search_date_end) && GETPOSTISSET('search } } +$arrayfields = array( + // 't.subledger_account'=>array('label'=>$langs->trans("SubledgerAccount"), 'checked'=>1), + 't.piece_num'=>array('label'=>$langs->trans("TransactionNumShort"), 'checked'=>1), + 't.doc_date'=>array('label'=>$langs->trans("Docdate"), 'checked'=>1), + 't.doc_ref'=>array('label'=>$langs->trans("Piece"), 'checked'=>1), + 't.label_operation'=>array('label'=>$langs->trans("Label"), 'checked'=>1), + 't.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1), + 't.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1), + 't.lettering_code'=>array('label'=>$langs->trans("LetteringCode"), 'checked'=>1), + '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'=>1), +); + +if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) unset($arrayfields['t.lettering_code']); + + $object = new BookKeeping($db); /* * Action */ -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers -{ - $search_doc_date = ''; - $search_accountancy_code = ''; - $search_accountancy_code_start = ''; - $search_accountancy_code_end = ''; - $search_label_account = ''; - $search_doc_ref = ''; - $search_label_operation = ''; - $search_direction = ''; - $search_ledger_code = ''; - $search_date_start = ''; - $search_date_end = ''; - $search_date_startyear = ''; - $search_date_startmonth = ''; - $search_date_startday = ''; - $search_date_endyear = ''; - $search_date_endmonth = ''; - $search_date_endday = ''; - $search_debit = ''; - $search_credit = ''; -} +$parameters = array('socid'=>$socid); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -// Must be after the remove filter action, before the export. -$param = ''; -$filter = array(); +if (empty($reshook)) { + include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php'; -if (!empty($search_date_start)) { - $filter['t.doc_date>='] = $search_date_start; - $param .= '&search_date_startmonth='.GETPOST('search_date_startmonth', 'int').'&search_date_startday='.GETPOST('search_date_startday', 'int').'&search_date_startyear='.GETPOST('search_date_startyear', 'int'); -} -if (!empty($search_date_end)) { - $filter['t.doc_date<='] = $search_date_end; - $param .= '&search_date_endmonth='.GETPOST('search_date_endmonth', 'int').'&search_date_endday='.GETPOST('search_date_endday', 'int').'&search_date_endyear='.GETPOST('search_date_endyear', 'int'); -} -if (!empty($search_doc_date)) { - $filter['t.doc_date'] = $search_doc_date; - $param .= '&doc_datemonth='.GETPOST('doc_datemonth', 'int').'&doc_dateday='.GETPOST('doc_dateday', 'int').'&doc_dateyear='.GETPOST('doc_dateyear', 'int'); -} -if (!empty($search_accountancy_code_start)) { - $filter['t.numero_compte>='] = $search_accountancy_code_start; - $param .= '&search_accountancy_code_start='.urlencode($search_accountancy_code_start); -} -if (!empty($search_accountancy_code_end)) { - $filter['t.numero_compte<='] = $search_accountancy_code_end; - $param .= '&search_accountancy_code_end='.urlencode($search_accountancy_code_end); -} -if (!empty($search_label_account)) { - $filter['t.label_compte'] = $search_label_account; - $param .= '&search_label_compte='.urlencode($search_label_account); -} -if (!empty($search_doc_ref)) { - $filter['t.doc_ref'] = $search_doc_ref; - $param .= '&search_doc_ref='.urlencode($search_doc_ref); -} -if (!empty($search_label_operation)) { - $filter['t.label_operation'] = $search_label_operation; - $param .= '&search_label_operation='.urlencode($search_label_operation); -} -if (!empty($search_direction)) { - $filter['t.sens'] = $search_direction; - $param .= '&search_direction='.urlencode($search_direction); -} -if (!empty($search_ledger_code)) { - $filter['t.code_journal'] = $search_ledger_code; - $param .= '&search_ledger_code='.urlencode($search_ledger_code); -} -if (!empty($search_debit)) { - $filter['t.debit'] = $search_debit; - $param .= '&search_debit='.urlencode($search_debit); -} -if (!empty($search_credit)) { - $filter['t.credit'] = $search_credit; - $param .= '&search_credit='.urlencode($search_credit); -} + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers + { + $search_doc_date = ''; + $search_accountancy_code = ''; + $search_accountancy_code_start = ''; + $search_accountancy_code_end = ''; + $search_label_account = ''; + $search_doc_ref = ''; + $search_label_operation = ''; + $search_direction = ''; + $search_ledger_code = ''; + $search_date_start = ''; + $search_date_end = ''; + $search_date_startyear = ''; + $search_date_startmonth = ''; + $search_date_startday = ''; + $search_date_endyear = ''; + $search_date_endmonth = ''; + $search_date_endday = ''; + $search_debit = ''; + $search_credit = ''; + } + // Must be after the remove filter action, before the export. + $param = ''; + $filter = array(); + + if (!empty($search_date_start)) { + $filter['t.doc_date>='] = $search_date_start; + $param .= '&search_date_startmonth=' . GETPOST('search_date_startmonth', 'int') . '&search_date_startday=' . GETPOST('search_date_startday', 'int') . '&search_date_startyear=' . GETPOST('search_date_startyear', 'int'); + } + if (!empty($search_date_end)) { + $filter['t.doc_date<='] = $search_date_end; + $param .= '&search_date_endmonth=' . GETPOST('search_date_endmonth', 'int') . '&search_date_endday=' . GETPOST('search_date_endday', 'int') . '&search_date_endyear=' . GETPOST('search_date_endyear', 'int'); + } + if (!empty($search_doc_date)) { + $filter['t.doc_date'] = $search_doc_date; + $param .= '&doc_datemonth=' . GETPOST('doc_datemonth', 'int') . '&doc_dateday=' . GETPOST('doc_dateday', 'int') . '&doc_dateyear=' . GETPOST('doc_dateyear', 'int'); + } + if (!empty($search_accountancy_code_start)) { + $filter['t.numero_compte>='] = $search_accountancy_code_start; + $param .= '&search_accountancy_code_start=' . urlencode($search_accountancy_code_start); + } + if (!empty($search_accountancy_code_end)) { + $filter['t.numero_compte<='] = $search_accountancy_code_end; + $param .= '&search_accountancy_code_end=' . urlencode($search_accountancy_code_end); + } + if (!empty($search_label_account)) { + $filter['t.label_compte'] = $search_label_account; + $param .= '&search_label_compte=' . urlencode($search_label_account); + } + if (!empty($search_doc_ref)) { + $filter['t.doc_ref'] = $search_doc_ref; + $param .= '&search_doc_ref=' . urlencode($search_doc_ref); + } + if (!empty($search_label_operation)) { + $filter['t.label_operation'] = $search_label_operation; + $param .= '&search_label_operation=' . urlencode($search_label_operation); + } + if (!empty($search_direction)) { + $filter['t.sens'] = $search_direction; + $param .= '&search_direction=' . urlencode($search_direction); + } + if (!empty($search_ledger_code)) { + $filter['t.code_journal'] = $search_ledger_code; + $param .= '&search_ledger_code=' . urlencode($search_ledger_code); + } + if (!empty($search_debit)) { + $filter['t.debit'] = $search_debit; + $param .= '&search_debit=' . urlencode($search_debit); + } + if (!empty($search_credit)) { + $filter['t.credit'] = $search_credit; + $param .= '&search_credit=' . urlencode($search_credit); + } +} if ($action == 'delmouvconfirm') { $mvt_num = GETPOST('mvt_num', 'int'); @@ -267,14 +299,25 @@ if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($l print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $result, $nbtotalofrecords, 'title_accountancy', 0, $viewflat.$newcardbutton, '', $limit); +$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; +$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields +if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); + +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook +if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; +else $moreforfilter = $hookmanager->resPrint; + // Reverse sort order if (preg_match('/^asc/i', $sortorder)) $sortorder = "asc"; else $sortorder = "desc"; print '
| ';
print ' ';
print $langs->trans('From').' ';
@@ -285,35 +328,64 @@ print $langs->trans('to').' ';
print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array(), 1, 1, 'maxwidth200');
print ' ';
print ' | ';
-print ''; +// Date document +if (!empty($arrayfields['t.doc_date']['checked'])) { + print ' | '; + print ' | ';
+ print $langs->trans('From') . ': ';
+ print $form->selectDate($search_date_start, 'search_date_start', 0, 0, 1);
+ print ' '; + print $langs->trans('to') . ': '; + print $form->selectDate($search_date_end, 'search_date_end', 0, 0, 1); + print ' | ';
+}
+// Ref document
+if (!empty($arrayfields['t.doc_ref']['checked'])) {
+ print ''; +} +// Label operation +if (!empty($arrayfields['t.label_operation']['checked'])) { + print ' | '; +} +// Debit +if (!empty($arrayfields['t.debit']['checked'])) { + print ' | '; +} +// Credit +if (!empty($arrayfields['t.credit']['checked'])) { + print ' | '; +} +// Code journal +if (!empty($arrayfields['t.code_journal']['checked'])) { + print ' | '; +} + +// Fields from hook +$parameters = array('arrayfields'=>$arrayfields); +$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook +print $hookmanager->resPrint; + +// Action column print ' | ';
-print $langs->trans('From').': ';
-print $form->selectDate($search_date_start, 'search_date_start', 0, 0, 1);
-print ' '; -print $langs->trans('to').': '; -print $form->selectDate($search_date_end, 'search_date_end', 0, 0, 1); -print ' | ';
-print ''; -print ' | '; -print ' | '; -print ' | '; -print ' | '; -print ' | '; -$searchpicto = $form->showFilterAndCheckAddButtons(0); +$searchpicto = $form->showFilterButtons(); print $searchpicto; print ' | '; -print '||||
| '; print ' | '.$line->piece_num.' | '; - print ''.dol_print_date($line->doc_date, 'day').' | '; - // TODO Add a link according to doc_type and fk_doc - print ''; - //if ($line->doc_type == 'supplier_invoice') - //if ($line->doc_type == 'customer_invoice') - print $line->doc_ref; + // Document date + if (!empty($arrayfields['t.doc_date']['checked'])) + { + print ' | '.dol_print_date($line->doc_date, 'day').' | '; + if (!$i) $totalarray['nbfield']++; + } + + // Document ref + if (!empty($arrayfields['t.doc_ref']['checked'])) + { + if ($line->doc_type == 'customer_invoice') + { + $langs->loadLangs(array('bills')); + + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + $objectstatic = new Facture($db); + $objectstatic->fetch($line->fk_doc); + //$modulepart = 'facture'; + + $filename = dol_sanitizeFileName($line->doc_ref); + $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref); + $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id; + $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir); + } + elseif ($line->doc_type == 'supplier_invoice') + { + $langs->loadLangs(array('bills')); + + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; + $objectstatic = new FactureFournisseur($db); + $objectstatic->fetch($line->fk_doc); + //$modulepart = 'invoice_supplier'; + + $filename = dol_sanitizeFileName($line->doc_ref); + $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref); + $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref); + $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir); + } + elseif ($line->doc_type == 'expense_report') + { + $langs->loadLangs(array('trips')); + + require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; + $objectstatic = new ExpenseReport($db); + $objectstatic->fetch($line->fk_doc); + //$modulepart = 'expensereport'; + + $filename = dol_sanitizeFileName($line->doc_ref); + $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref); + $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id; + $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir); + } + else + { + // Other type + } + + print '';
+
+ print '
| \n";
+ if (!$i) $totalarray['nbfield']++;
+ }
+
+ // Label operation
+ if (!empty($arrayfields['t.label_operation']['checked'])) {
+ // Affiche un lien vers la facture client/fournisseur
+ $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref);
+ print strlen(length_accounta($line->subledger_account)) == 0 ? '' . $line->label_operation . ' | ' : '' . $line->label_operation . ' (' . length_accounta($line->subledger_account) . ') | ';
+ if (!$i) $totalarray['nbfield']++;
+ }
+
+ // Amount debit
+ if (!empty($arrayfields['t.debit']['checked']))
+ {
+ print ''.($line->debit ? price($line->debit) : '').' | '; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit'; + $totalarray['val']['totaldebit'] += $line->debit; + } + + // Amount credit + if (!empty($arrayfields['t.credit']['checked'])) { + print '' . ($line->credit ? price($line->credit) : '') . ' | '; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit'; + $totalarray['val']['totalcredit'] += $line->credit; + } + + // Lettering code + if (!empty($arrayfields['t.lettering_code']['checked'])) + { + print ''.$line->lettering_code.' | '; + if (!$i) $totalarray['nbfield']++; + } + + // Journal code + if (!empty($arrayfields['t.code_journal']['checked'])) + { + $accountingjournal = new AccountingJournal($db); + $result = $accountingjournal->fetch('', $line->code_journal); + $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal); + print ''.$journaltoshow.' | '; + } + + // Fields from hook + $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj); + $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + // Action column + print ''; + if (empty($line->date_export)) { + if ($user->rights->accounting->mouvements->creer) { + print ''.img_edit().''; + } + if ($user->rights->accounting->mouvements->supprimer) { + print ' '.img_delete().''; + } + } print ' | '; - // Affiche un lien vers la facture client/fournisseur - $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref); - print strlen(length_accounta($line->subledger_account)) == 0 ? ''.$line->label_operation.' | ' : ''.$line->label_operation.' ('.length_accounta($line->subledger_account).') | ';
-
-
- print ''.($line->debit ? price($line->debit) : '').' | '; - print ''.($line->credit ? price($line->credit) : '').' | '; - - $accountingjournal = new AccountingJournal($db); - $result = $accountingjournal->fetch('', $line->code_journal); - $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal); - print ''.$journaltoshow.' | '; - - print ''; - print ''.img_edit().' '; - print ''.img_delete().''; - print ' | '; - print "'; print ''; +// Show total line +include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; -// Show total -print ' |
| '.$langs->trans("Total").': | '; -print ''; -print price($total_debit); -print ' | '; -print ''; -print price($total_credit); -print ' | '; -print ''; -print ' | '; -print ' | |||||||||||||||