Start debug compta-files
This commit is contained in:
parent
0eb9985366
commit
889ce7fc5d
@ -25,10 +25,12 @@ require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
|
||||
|
||||
restrictedArea($user,'banque');
|
||||
|
||||
@ -78,113 +80,128 @@ $arrayfields=array(
|
||||
//$reshook = $hookmanager->executeHooks('doActions', $parameters, $object); // Note that $object may have been modified by some hooks
|
||||
//if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$filesarray=array();
|
||||
$result=false;
|
||||
if(($action=="searchfiles"||$action=="dl" ) && $date_start && $date_stop){
|
||||
$wheretail=" '".$db->idate($date_start)."' AND '".$db->idate($date_stop)."'";
|
||||
$sql="SELECT rowid as id, ref as ref,paye as paid,total_ttc,fk_soc,datef as date, 'Invoice' as item FROM ".MAIN_DB_PREFIX."facture";
|
||||
$sql="SELECT rowid as id, ref as ref,paye as paid, total_ttc, fk_soc, datef as date, 'Invoice' as item FROM ".MAIN_DB_PREFIX."facture";
|
||||
$sql.=" WHERE datef between ".$wheretail;
|
||||
$sql.=" UNION ALL";
|
||||
$sql.=" SELECT rowid as id,ref, paye as paid, total_ttc, fk_soc,datef as date, 'InvoiceSupplier' as item FROM ".MAIN_DB_PREFIX."facture_fourn";
|
||||
$sql.=" WHERE datef between ".$wheretail;
|
||||
$sql.=" SELECT rowid as id, ref, paye as paid, total_ttc, fk_soc, datef as date, 'InvoiceSupplier' as item FROM ".MAIN_DB_PREFIX."facture_fourn";
|
||||
$sql.=" WHERE datef between ".$wheretail;
|
||||
$sql.=" UNION ALL";
|
||||
$sql.=" SELECT rowid as id,ref,paid,total_ttc,fk_user_author as fk_soc,date_fin as date,'Expense' as item FROM ".MAIN_DB_PREFIX."expensereport";
|
||||
$sql.=" SELECT rowid as id, ref, paid, total_ttc, fk_user_author as fk_soc, date_fin as date,'ExpenseReport' as item FROM ".MAIN_DB_PREFIX."expensereport";
|
||||
$sql.=" WHERE date_fin between ".$wheretail;
|
||||
$sql.=" UNION ALL";
|
||||
$sql.=" SELECT rowid as id,ref,paid,amount as total_ttc,'0' as fk_soc,datedon as date,'Donation' as item FROM ".MAIN_DB_PREFIX."don";
|
||||
$sql.=" WHERE datedon between ".$wheretail;
|
||||
$sql.=" SELECT rowid as id, ref,paid,amount as total_ttc, '0' as fk_soc, datedon as date,'Donation' as item FROM ".MAIN_DB_PREFIX."don";
|
||||
$sql.=" WHERE datedon between ".$wheretail;
|
||||
$sql.=" UNION ALL";
|
||||
$sql.=" SELECT rowid as id,label as ref,1 as paid,amount as total_ttc,fk_user as fk_soc,datep as date,'Salary' as item FROM ".MAIN_DB_PREFIX."payment_salary";
|
||||
$sql.=" WHERE datep between ".$wheretail;
|
||||
$sql.=" SELECT rowid as id, label as ref, 1 as paid, amount as total_ttc, fk_user as fk_soc,datep as date,'SalaryPayment' as item FROM ".MAIN_DB_PREFIX."payment_salary";
|
||||
$sql.=" WHERE datep between ".$wheretail;
|
||||
$sql.=" UNION ALL";
|
||||
$sql.=" SELECT rowid as id,num_paiement as ref,1 as paid,amount as total_ttc,fk_charge as fk_soc,datep as date,'Charge' as item FROM ".MAIN_DB_PREFIX."paiementcharge";
|
||||
$sql.=" WHERE datep between ".$wheretail;
|
||||
$sql.=" SELECT rowid as id, libelle as ref, paye as paid, amount as total_ttc, 0 as fk_soc, date_creation as date, 'SocialContributions' as item FROM ".MAIN_DB_PREFIX."chargesociales";
|
||||
$sql.=" WHERE date_creation between ".$wheretail;
|
||||
$resd = $db->query($sql);
|
||||
$files=array();
|
||||
$link='';
|
||||
|
||||
if ($resd)
|
||||
{
|
||||
{
|
||||
$numd = $db->num_rows($resd);
|
||||
|
||||
$upload_dir ='';
|
||||
$tmpinvoice=new Facture($db);
|
||||
$tmpinvoicesupplier=new FactureFournisseur($db);
|
||||
$tmpdonation=new Don($db);
|
||||
|
||||
$upload_dir ='';
|
||||
$i=0;
|
||||
while($i<$numd)
|
||||
{
|
||||
|
||||
|
||||
$objd = $db->fetch_object($resd);
|
||||
|
||||
switch($objd->item){
|
||||
case "Invoice":
|
||||
$subdir=dol_sanitizeFileName($objd->ref);
|
||||
$upload_dir = $conf->facture->dir_output.'/'.$subdir;
|
||||
$link="../../document.php?modulepart=facture&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
case "InvoiceSupplier":
|
||||
$subdir=get_exdir($objd->id,2,0,0,$objd,'invoice_supplier').dol_sanitizeFileName($objd->ref);
|
||||
$upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir;
|
||||
$link="../../document.php?modulepart=facture_fournisseur&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
case "Expense":
|
||||
$subdir=dol_sanitizeFileName($objd->ref);
|
||||
$upload_dir = $conf->expensereport->dir_output.'/'.$subdir;
|
||||
$link="../../document.php?modulepart=expensereport&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
case "Salary":
|
||||
$subdir=dol_sanitizeFileName($objd->id);
|
||||
$upload_dir = $conf->salaries->dir_output.'/'.$subdir;
|
||||
$link="../../document.php?modulepart=salaries&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
case "Donation":
|
||||
$subdir=get_exdir(null,2,0,1,$objd,'donation'). '/'. dol_sanitizeFileName($objd->id);
|
||||
$upload_dir = $conf->don->dir_output . '/' . $subdir;
|
||||
$link="../../document.php?modulepart=don&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
case "Charge":
|
||||
$subdir=dol_sanitizeFileName($objd->id);
|
||||
$upload_dir = $conf->tax->dir_output . '/' . $subdir;
|
||||
$link="../../document.php?modulepart=tax&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch($objd->item)
|
||||
{
|
||||
case "Invoice":
|
||||
$subdir=dol_sanitizeFileName($objd->ref);
|
||||
$upload_dir = $conf->facture->dir_output.'/'.$subdir;
|
||||
$link="../../document.php?modulepart=facture&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
case "InvoiceSupplier":
|
||||
$tmpinvoicesupplier->fetch($objd->id);
|
||||
$subdir=get_exdir(0,0,0,1,$tmpinvoicesupplier,'invoice_supplier').'/'.dol_sanitizeFileName($objd->ref);
|
||||
$upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir;
|
||||
$link="../../document.php?modulepart=facture_fournisseur&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
case "Expense":
|
||||
$subdir=dol_sanitizeFileName($objd->ref);
|
||||
$upload_dir = $conf->expensereport->dir_output.'/'.$subdir;
|
||||
$link="../../document.php?modulepart=expensereport&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
case "Salary":
|
||||
$subdir=dol_sanitizeFileName($objd->id);
|
||||
$upload_dir = $conf->salaries->dir_output.'/'.$subdir;
|
||||
$link="../../document.php?modulepart=salaries&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
case "Donation":
|
||||
$tmpdonation->fetch($objp->id);
|
||||
$subdir=get_exdir(0,0,0,1,$tmpdonation,'donation'). '/'. dol_sanitizeFileName($objd->id);
|
||||
$upload_dir = $conf->don->dir_output . '/' . $subdir;
|
||||
$link="../../document.php?modulepart=don&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
case "SocialContributions":
|
||||
$subdir=dol_sanitizeFileName($objd->id);
|
||||
$upload_dir = $conf->tax->dir_output . '/' . $subdir;
|
||||
$link="../../document.php?modulepart=tax&file=".str_replace('/','%2F',$subdir).'%2F';
|
||||
break;
|
||||
default:
|
||||
$subdir='';
|
||||
$upload_dir='';
|
||||
$link='';
|
||||
break;
|
||||
}
|
||||
|
||||
if(!empty($upload_dir)){
|
||||
if (!empty($upload_dir))
|
||||
{
|
||||
$result=true;
|
||||
$files=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$','',SORT_ASC,1);
|
||||
foreach ($files as $key => $file){
|
||||
$file['date']=$db->idate($objd->date);
|
||||
$file['paid']=$objd->paid;
|
||||
$file['amount']=$objd->total_ttc;
|
||||
$file['ref']=$objd->ref;
|
||||
$file['fk']=$objd->fk_soc;
|
||||
$file['item']=$objd->item;
|
||||
$file['link']=$link.$file['name'];
|
||||
$out.= '<br><a href="'.$link.$file['name'].'">'.$file['name'].'</a>';
|
||||
$filesarray[]=$file;
|
||||
}
|
||||
if(count($files)<1){
|
||||
$files=dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview\.png)$', '', SORT_ASC, 1);
|
||||
if (count($files)<1) {
|
||||
$nofile['date']=$db->idate($objd->date);
|
||||
$nofile['paid']=$objd->paid;
|
||||
$nofile['amount']=$objd->total_ttc;
|
||||
$nofile['ref']=$objd->ref;
|
||||
$nofile['fk']=$objd->fk_soc;
|
||||
$nofile['item']=$objd->item;
|
||||
$filesarray[]=$nofile;
|
||||
|
||||
$filesarray[]=$nofile;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($files as $key => $file)
|
||||
{
|
||||
$file['date']=$db->idate($objd->date);
|
||||
$file['paid']=$objd->paid;
|
||||
$file['amount']=$objd->total_ttc;
|
||||
$file['ref']=$objd->ref;
|
||||
$file['fk']=$objd->fk_soc;
|
||||
$file['item']=$objd->item;
|
||||
$file['link']=$link.$file['name'];
|
||||
$file['relpathnamelang'] = $langs->trans($file['item']).'/'.$file['name'];
|
||||
|
||||
$filesarray[]=$file;
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
$db->free($resd);
|
||||
}
|
||||
|
||||
/*
|
||||
* cleanup of old ZIP
|
||||
*/
|
||||
@ -192,33 +209,42 @@ if(($action=="searchfiles"||$action=="dl" ) && $date_start && $date_stop){
|
||||
/*
|
||||
*ZIP creation
|
||||
*/
|
||||
if($result & $action=="dl"){
|
||||
unset($zip);
|
||||
$log='date,type,ref,total,paid,filename,item_id'."\n";
|
||||
$zipname = ($date_start)."-".($date_stop).'_export.zip';
|
||||
$zip = new ZipArchive;
|
||||
$res = $zip->open($zipname, ZipArchive::OVERWRITE|ZipArchive::CREATE);
|
||||
if ($res){
|
||||
foreach ($filesarray as $key=> $file) {
|
||||
if(file_exists($file["fullname"])) $zip->addFile($file["fullname"],$file["name"]);//
|
||||
$log.=$file['date'].','.$file['item'].','.$file['ref'].','.$file['amount'].','.$file['paid'].','.$file["name"].','.$file['fk']."\n";
|
||||
}
|
||||
$zip->addFromString('log.csv', $log);
|
||||
$zip->close();
|
||||
///Then download the zipped file.
|
||||
header('Content-Type: application/zip');
|
||||
header('Content-disposition: attachment; filename='.$zipname);
|
||||
header('Content-Length: ' . filesize($zipname));
|
||||
readfile($zipname);
|
||||
unlink($zipname);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
// None
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
if ($result && $action == "dl")
|
||||
{
|
||||
dol_delete_file($zip);
|
||||
|
||||
$log='date,type,ref,total,paid,filename,item_id'."\n";
|
||||
$zipname = $conf->accounting->dir_temp.'/'.($date_start)."-".($date_stop).'_export.zip';
|
||||
|
||||
$zip = new ZipArchive;
|
||||
$res = $zip->open($zipname, ZipArchive::OVERWRITE|ZipArchive::CREATE);
|
||||
if ($res)
|
||||
{
|
||||
foreach ($filesarray as $key=> $file)
|
||||
{
|
||||
if (file_exists($file["fullname"])) $zip->addFile($file["fullname"], $file["relpathnamelang"]); //
|
||||
$log.=$file['date'].','.$file['item'].','.$file['ref'].','.$file['amount'].','.$file['paid'].','.$file["name"].','.$file['fk']."\n";
|
||||
}
|
||||
$zip->addFromString('log.csv', $log);
|
||||
$zip->close();
|
||||
|
||||
///Then download the zipped file.
|
||||
header('Content-Type: application/zip');
|
||||
header('Content-disposition: attachment; filename='.basename($zipname));
|
||||
header('Content-Length: ' . filesize($zipname));
|
||||
readfile($zipname);
|
||||
|
||||
dol_delete_file($zipname);
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader('',$title,$help_url);
|
||||
|
||||
@ -226,16 +252,42 @@ $h=0;
|
||||
$head[$h][0] = $_SERVER["PHP_SELF"].$varlink;
|
||||
$head[$h][1] = $langs->trans("AccountantFiles");
|
||||
$head[$h][2] = 'AccountantFiles';
|
||||
|
||||
dol_fiche_head($head, 'AccountantFiles');
|
||||
|
||||
$form = new Form($db);
|
||||
$userstatic=new User($db);
|
||||
$title=$langs->trans("ComptaFiles").' - '.$langs->trans("List");
|
||||
print '<div><form name="searchfiles" action="?action=searchfiles'.$tail.'" method="POST" >'."\n\t\t\t";
|
||||
print '<a>'.$langs->trans("ReportPeriod").': '.$form->select_date($date_start,'date_start',0,0,0,"",1,1,1);
|
||||
print ' - '.$form->select_date($date_stop,'date_stop',0,0,0,"",1,1,1)."\n</a>";
|
||||
print '<input class="butAction" type="submit" value="'.$langs->trans("Refresh").'" /></form></div>'."\n\t\t";
|
||||
if (!empty($date_start) && !empty($date_stop)){
|
||||
print '<form name="searchfiles" action="?action=searchfiles'.$tail.'" method="POST" >'."\n";
|
||||
print $langs->trans("ReportPeriod").': '.$form->select_date($date_start,'date_start',0,0,0,"",1,1,1);
|
||||
print ' - '.$form->select_date($date_stop,'date_stop',0,0,0,"",1,1,1)."\n</a>";
|
||||
print '<input class="butAction" type="submit" value="'.$langs->trans("Refresh").'" /></form>'."\n";
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
if (!empty($date_start) && !empty($date_stop))
|
||||
{
|
||||
print '<form name="dl" action="?action=dl" method="POST" >'."\n";
|
||||
|
||||
echo dol_print_date($date_start)." - ".dol_print_date($date_stop);
|
||||
|
||||
print '<input type="hidden" name="date_start" value="'.dol_print_date($date_start,'dayxcard').'" />';
|
||||
print '<input type="hidden" name="date_stop" value="'.dol_print_date($date_stop, 'dayxcard').'" />';
|
||||
|
||||
//print '<input type="hidden" name="date_stopDay" value="'.dol_print_date($date_stop, '%d').'" />';
|
||||
//print '<input type="hidden" name="date_stopMonth" value="'.dol_print_date($date_stop, '%m').'" />';
|
||||
//print '<input type="hidden" name="date_stopYear" value="'.dol_print_date($date_stop, '%Y').'" />';
|
||||
|
||||
//print '<input type="hidden" name="date_startDay" value="'.dol_print_date($date_start, '%d').'" />';
|
||||
//print '<input type="hidden" name="date_startMonth" value="'.dol_print_date($date_start, '%m').'" />';
|
||||
//print '<input type="hidden" name="date_startYear" value="'.dol_print_date($date_start, '%m').'" />';
|
||||
|
||||
print '<input class="butAction" type="submit" value="'.$langs->trans("Download").'" />';
|
||||
print '</form>'."\n";
|
||||
|
||||
print '<br>';
|
||||
|
||||
print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print_liste_field_titre($arrayfields['date']['label'],$_SERVER["PHP_SELF"],"date","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
|
||||
@ -279,8 +331,11 @@ if (!empty($date_start) && !empty($date_stop)){
|
||||
print dol_print_date($data['date'],'day');
|
||||
print "</td>\n";
|
||||
print '<td aling="left">'.$data['item'].'</td>';
|
||||
print '<td aling="left">'.$data['ref'].'</td>';
|
||||
print '<td> <a href='.$data['link'].">".$data['name']."</a></td>\n";
|
||||
print '<td aling="left">'.$data['ref'].'</td>';
|
||||
|
||||
// File link
|
||||
print '<td><a href='.$data['link'].">".$data['name']."</a></td>\n";
|
||||
|
||||
print '<td aling="left">'.$data['paid'].'</td>';
|
||||
print '<td align="right">'.(($data['amount'] > 0) ? price(abs($data['amount'])) : '')."</td>\n";
|
||||
$totalDebit += ($data['amount'] > 0) ? abs($data['amount']) : 0;
|
||||
@ -295,25 +350,11 @@ if (!empty($date_start) && !empty($date_stop)){
|
||||
print '<td align="right">'.price($totalDebit).'</td>';
|
||||
print '<td align="right">'.price($totalCredit).'</td>';
|
||||
print '<td align="right">'.price(price2num($totalDebit - $totalCredit, 'MT')).'</td>';
|
||||
print '<td></td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
}
|
||||
print "</table>";
|
||||
print '<form name="dl" action="?action=dl" method="POST" >'."\n\t\t\t";
|
||||
|
||||
print '<input type="hidden" name="date_start" value="'.dol_print_date($date_start,'dayxcard').'" />';
|
||||
print '<input type="hidden" name="date_stop" value="'.dol_print_date($date_stop, 'dayxcard').'" />';
|
||||
|
||||
//print '<input type="hidden" name="date_stopDay" value="'.dol_print_date($date_stop, '%d').'" />';
|
||||
//print '<input type="hidden" name="date_stopMonth" value="'.dol_print_date($date_stop, '%m').'" />';
|
||||
//print '<input type="hidden" name="date_stopYear" value="'.dol_print_date($date_stop, '%Y').'" />';
|
||||
|
||||
//print '<input type="hidden" name="date_startDay" value="'.dol_print_date($date_start, '%d').'" />';
|
||||
//print '<input type="hidden" name="date_startMonth" value="'.dol_print_date($date_start, '%m').'" />';
|
||||
//print '<input type="hidden" name="date_startYear" value="'.dol_print_date($date_start, '%m').'" />';
|
||||
|
||||
print '<input class="butAction" type="submit" value="'.$langs->trans("Download").'" /></form>'."\n\t\t</th>\n\t\t<th>\n\t\t\t";
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user