Fix selection of fields

This commit is contained in:
Laurent Destailleur 2016-11-16 21:24:51 +01:00
parent 3dc9bc89d8
commit 7f5fd3bbc0

View File

@ -414,148 +414,172 @@ print '</tr>';
$total = array(); $found = 0; $total = array(); $found = 0; $i=0;
$var=true; $var=true;
foreach ($accounts as $key=>$type) foreach ($accounts as $key=>$type)
{ {
//if ($type == 1) $found++;
//{
$found++;
$acc = new Account($db); $acc = new Account($db);
$acc->fetch($key); $acc->fetch($key);
$var = !$var; $var = !$var;
$solde = $acc->solde(1); $solde = $acc->solde(1);
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
// Ref // Ref
if (! empty($arrayfields['b.ref']['checked'])) if (! empty($arrayfields['b.ref']['checked']))
{ {
print '<td class="titlefield">'.$acc->getNomUrl(1).'</td>'; print '<td class="titlefield">'.$acc->getNomUrl(1).'</td>';
} if (! $i) $totalarray['nbfield']++;
}
// Label // Label
if (! empty($arrayfields['b.label']['checked'])) if (! empty($arrayfields['b.label']['checked']))
{ {
print '<td>'.$acc->label.'</td>'; print '<td>'.$acc->label.'</td>';
} if (! $i) $totalarray['nbfield']++;
}
// Account type // Account type
if (! empty($arrayfields['accountype']['checked'])) if (! empty($arrayfields['accountype']['checked']))
{ {
print '<td>'; print '<td>';
print $acc->type_lib[$acc->type]; print $acc->type_lib[$acc->type];
print '</td>'; print '</td>';
} if (! $i) $totalarray['nbfield']++;
}
// Number // Number
if (! empty($arrayfields['b.number']['checked'])) if (! empty($arrayfields['b.number']['checked']))
{ {
print '<td>'.$acc->number.'</td>'; print '<td>'.$acc->number.'</td>';
} if (! $i) $totalarray['nbfield']++;
}
// Account number // Account number
if (! empty($arrayfields['b.account_number']['checked'])) if (! empty($arrayfields['b.account_number']['checked']))
{ {
include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
print '<td>'.length_accountg($acc->account_number).'</td>'; print '<td>'.length_accountg($acc->account_number).'</td>';
} if (! $i) $totalarray['nbfield']++;
}
// Transactions to reconcile // Transactions to reconcile
if (! empty($arrayfields['toreconcile']['checked'])) if (! empty($arrayfields['toreconcile']['checked']))
{ {
print '<td align="center">'; print '<td align="center">';
if ($acc->rappro) if ($acc->rappro)
{
$result=$acc->load_board($user,$acc->id);
if ($result<0) {
setEventMessages($acc->error, $acc->errors, 'errors');
} else {
print $result->nbtodo;
if ($result->nbtodolate) print ' &nbsp; ('.$result->nbtodolate.img_warning($langs->trans("Late")).')';
}
}
else print $langs->trans("FeatureDisabled");
print '</td>';
}
// Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{ {
foreach($extrafields->attribute_label as $key => $val) $result=$acc->load_board($user,$acc->id);
{ if ($result<0) {
if (! empty($arrayfields["ef.".$key]['checked'])) setEventMessages($acc->error, $acc->errors, 'errors');
{ } else {
print '<td'; print $result->nbtodo;
$align=$extrafields->getAlignFlag($key); if ($result->nbtodolate) print ' &nbsp; ('.$result->nbtodolate.img_warning($langs->trans("Late")).')';
if ($align) print ' align="'.$align.'"'; }
print '>';
$tmpkey='options_'.$key;
print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
}
} }
// Fields from hook else print $langs->trans("FeatureDisabled");
$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); print '</td>';
$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook if (! $i) $totalarray['nbfield']++;
print $hookmanager->resPrint; }
// Date creation
if (! empty($arrayfields['b.datec']['checked']))
{
print '<td align="center">';
print dol_print_date($acc->date_creation, 'dayhour');
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
// Date modification
if (! empty($arrayfields['b.tms']['checked']))
{
print '<td align="center">';
print dol_print_date($acc->date_update, 'dayhour');
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
// Statut
if (! empty($arrayfields['b.clos']['checked']))
{
print '<td align="center">'.$acc->getLibStatut(5).'</td>';
}
// Balance // Extra fields
if (! empty($arrayfields['balance']['checked'])) if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{ {
print '<td align="right">'; foreach($extrafields->attribute_label as $key => $val)
print '<a href="'.DOL_URL_ROOT.'/compta/bankentries.php?id='.$acc->id.'">'.price($solde, 0, $langs, 0, 0, -1, $acc->currency_code).'</a>'; {
print '</td>'; if (! empty($arrayfields["ef.".$key]['checked']))
} {
print '<td';
$align=$extrafields->getAlignFlag($key);
if ($align) print ' align="'.$align.'"';
print '>';
$tmpkey='options_'.$key;
print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
}
}
// 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;
// Date creation
if (! empty($arrayfields['b.datec']['checked']))
{
print '<td align="center">';
print dol_print_date($acc->date_creation, 'dayhour');
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
// Date modification
if (! empty($arrayfields['b.tms']['checked']))
{
print '<td align="center">';
print dol_print_date($acc->date_update, 'dayhour');
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
// Action column // Statut
print '<td class="nowrap" align="center">'; if (! empty($arrayfields['b.clos']['checked']))
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined {
{ print '<td align="center">'.$acc->getLibStatut(5).'</td>';
$selected=0; if (! $i) $totalarray['nbfield']++;
if (in_array($obj->rowid, $arrayofselected)) $selected=1; }
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
} // Balance
if (! empty($arrayfields['balance']['checked']))
{
print '<td align="right">';
print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries.php?id='.$acc->id.'">'.price($solde, 0, $langs, 0, 0, -1, $acc->currency_code).'</a>';
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
if (! $i) $totalarray['totalbalancefield']=$totalarray['nbfield'];
$totalarray['totalbalance'] += $solde;
}
print '</tr>'; // Action column
print '<td class="nowrap" align="center">';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
$selected=0;
if (in_array($obj->rowid, $arrayofselected)) $selected=1;
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
}
print '</td>';
if (! $i) $totalarray['nbfield']++;
$total[$acc->currency_code] += $solde; print '</tr>';
//}
$total[$acc->currency_code] += $solde;
$i++;
} }
if (! $found) print '<tr '.$bc[$var].'><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
// Total if (! $found) print '<tr '.$bc[$var].'><td colspan="'.$totalarray['nbfield'].'" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
foreach ($total as $key=>$solde)
// Show total line
if (isset($totalarray['totalbalancefield']))
{ {
print '<tr class="liste_total"><td colspan="6" class="liste_total">'.$langs->trans("Total").' '.$key.'</td><td align="right" class="liste_total">'.price($solde, 0, $langs, 0, 0, -1, $key).'</td><td></td></tr>'; print '<tr class="liste_total">';
$i=0;
while ($i < $totalarray['nbfield'])
{
$i++;
if ($i == 1)
{
if ($num < $limit) print '<td align="left">'.$langs->trans("Total").'</td>';
else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
}
elseif ($totalarray['totalbalancefield'] == $i) print '<td align="right">'.price($totalarray['totalbalance'], 0, $langs, 0, 0, -1, $key).'</td>';
else print '<td></td>';
}
print '</tr>';
} }
print '</table>'; print '</table>';