diff --git a/htdocs/compta/compta-files.php b/htdocs/compta/compta-files.php
index d8f4885a3b2..61b05f81e37 100644
--- a/htdocs/compta/compta-files.php
+++ b/htdocs/compta/compta-files.php
@@ -25,166 +25,207 @@ 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.'/expensereport/class/expensereport.class.php';
+require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
-restrictedArea($user,'banque');
+$langs->loadLangs(array("accountancy","bills"));
-$langs->load("companies");
-if (! empty($conf->facture->enabled)) $langs->load("bills");
-$date_start =GETPOST('date_start','alpha');
-$date_startDay= GETPOST('date_startday','int');
-$date_startMonth= GETPOST('date_startmonth','int');
-$date_startYear= GETPOST('date_startyear','int');
-$date_start=($date_startDay)?dol_mktime(0,0,0,$date_startMonth,$date_startDay,$date_startYear):strtotime($date_start);
-$date_stop =GETPOST('date_stop','alpha');
-$date_stopDay= GETPOST('date_stopday','int');
-$date_stopMonth= GETPOST('date_stopmonth','int');
-$date_stopYear= GETPOST('date_stopyear','int');
+$date_start =GETPOST('date_start', 'alpha');
+$date_startDay= GETPOST('date_startday', 'int');
+$date_startMonth= GETPOST('date_startmonth', 'int');
+$date_startYear= GETPOST('date_startyear', 'int');
+$date_start=($date_startDay)?dol_mktime(0, 0, 0, $date_startMonth, $date_startDay, $date_startYear):strtotime($date_start);
+$date_stop =GETPOST('date_stop', 'alpha');
+$date_stopDay= GETPOST('date_stopday', 'int');
+$date_stopMonth= GETPOST('date_stopmonth', 'int');
+$date_stopYear= GETPOST('date_stopyear', 'int');
//FIXME doldate
-$date_stop=($date_stopDay)?dol_mktime(0,0,0,$date_stopMonth,$date_stopDay,$date_stopYear):strtotime($date_stop);
-$action =GETPOST('action','alpha');
-// Security check
-//if ($user->societe_id) $id=$user->societe_id;
-//$result = restrictedArea($user, 'societe', $id, '&societe');
-//$object = new Societe($db);
-//if ($id > 0) $object->fetch($id);
+$date_stop=($date_stopDay)?dol_mktime(0, 0, 0, $date_stopMonth, $date_stopDay, $date_stopYear):strtotime($date_stop);
+$action =GETPOST('action', 'alpha');
+
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
-$hookmanager->initHooks(array('comptafilescard','globalcard'));
+$hookmanager->initHooks(array('comptafileslist','globallist'));
+
// Load variable for pagination
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
-$sortfield = GETPOST('sortfield','alpha');
-$sortorder = GETPOST('sortorder','alpha');
-$page = GETPOST('page','int');
+$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit;
+$sortfield = GETPOST('sortfield', 'alpha');
+$sortorder = GETPOST('sortorder', 'alpha');
+$page = GETPOST('page', 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
-if (! $sortfield) $sortfield="f.datef,f.rowid"; // Set here default search field
+if (! $sortfield) $sortfield="date,item"; // Set here default search field
if (! $sortorder) $sortorder="DESC";
+
+
$arrayfields=array(
'date'=>array('label'=>"Date", 'checked'=>1),
//...
);
+// Security check
+if (empty($conf->compta->enabled) && empty($conf->accounting->enabled)) {
+ accessforbidden();
+}
+if ($user->societe_id > 0)
+ accessforbidden();
+
+
/*
* Actions
*/
+$entity = GETPOST('entity','int')?GETPOST('entity','int'):$conf->entity;
+
//$parameters = array('socid' => $id);
//$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, facnumber 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, facnumber 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.=" AND entity IN (".($entity==1?'0,1':$entity).')';
+ $sql.=" AND fk_statut <> ".Facture::STATUS_DRAFT;
$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, 'SupplierInvoice' as item FROM ".MAIN_DB_PREFIX."facture_fourn";
+ $sql.=" WHERE datef between ".$wheretail;
+ $sql.=" AND entity IN (".($entity==1?'0,1':$entity).')';
+ $sql.=" AND fk_statut <> ".FactureFournisseur::STATUS_DRAFT;
$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.=" AND entity IN (".($entity==1?'0,1':$entity).')';
+ $sql.=" AND fk_statut <> ".ExpenseReport::STATUS_DRAFT;
$sql.=" UNION ALL";
- $sql.=" SELECT rowid as id,ref,paid,amount as total_ttc,CONCAT(firstname,' ',lastname) 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.=" AND entity IN (".($entity==1?'0,1':$entity).')';
+ $sql.=" AND fk_statut <> ".Don::STATUS_DRAFT;
$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.=" AND entity IN (".($entity==1?'0,1':$entity).')';
+ //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT;
$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;
+ $sql.=" AND entity IN (".($entity==1?'0,1':$entity).')';
+ //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT;
+ $sql.= $db->order($sortfield, $sortorder);
+
$resd = $db->query($sql);
$files=array();
$link='';
if ($resd)
- {
- $numd = $db->num_rows($resd);
+ {
+ $numd = $db->num_rows($resd);
+
+ $tmpinvoice=new Facture($db);
+ $tmpinvoicesupplier=new FactureFournisseur($db);
+ $tmpdonation=new Don($db);
$upload_dir ='';
- $i=0;
- while($i<$numd)
- {
-
-
+ $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 "SupplierInvoice":
+ $tmpinvoicesupplier->fetch($objd->id);
+ $subdir=get_exdir($tmpinvoicesupplier->id, 2, 0, 0, $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 "ExpenseReport":
+ $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 "SalaryPayment":
+ $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.= '
'.$file['name'].'';
- $filesarray[]=$file;
- }
- if(count($files)<1){
+ $files=dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview\.png)$', '', SORT_ASC, 1);
+ //var_dump($upload_dir);
+ 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++;
- }
- }
- $db->free($resd);
+ $i++;
+ }
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+
+ $db->free($resd);
}
+
/*
* cleanup of old ZIP
*/
@@ -192,124 +233,202 @@ 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();
+
+if ($result && $action == "dl")
+{
+ dol_delete_file($zip);
+
+ $log='date,type,ref,total,paid,filename,item_id'."\n";
+ $zipname = ($conf->accounting->dir_temp ? $conf->accounting->dir_temp : $conf->compta->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('transactions.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();
+ }
}
-// None
+
+
/*
- * View
+ * View
*/
+
$form = new Form($db);
$userstatic=new User($db);
+
$title=$langs->trans("ComptaFiles").' - '.$langs->trans("List");
-//if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Symmary");
-$help_url='EN:Module_Accounting|FR:Module_Compatibilite'; //FIXME
-llxHeader('',$title,$help_url);
-print '
'."\n\t\t";
-if (!empty($date_start) && !empty($date_stop))echo dol_print_date($date_start)." - ".dol_print_date($date_stop);
-print '';
-print '';
-//if (! empty($arrayfields['f.datef']['checked']))
-print_liste_field_titre($arrayfields['date']['label'],$_SERVER["PHP_SELF"],"date","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
-print '| '.$langs->trans("Type").' | ';
-print ''.$langs->trans("Ref").' | ';
-print ''.$langs->trans("File").' | ';
-print ''.$langs->trans("Paid").' | ';
-print ''.$langs->trans("Debit").' | ';
-print ''.$langs->trans("Credit").' | ';
-print ''.$langs->trans("Balance").' | ';
-print '
';
-if ($result)
+
+llxHeader('', $title, $help_url);
+
+$h=0;
+$head[$h][0] = $_SERVER["PHP_SELF"].$varlink;
+$head[$h][1] = $langs->trans("AccountancyFiles");
+$head[$h][2] = 'AccountancyFiles';
+
+dol_fiche_head($head, 'AccountancyFiles');
+
+
+print '
";
-print ''."\n";
-//print '';
-//print '';
-//print '';
+dol_fiche_end();
-//print '';
-//print '';
-//print '';
+if (!empty($date_start) && !empty($date_stop))
+{
+ $param='action=searchfiles';
+ $param.='&date_startday='.GETPOST('date_startday', 'int');
+ $param.='&date_startmonth='.GETPOST('date_startmonth', 'int');
+ $param.='&date_startyear='.GETPOST('date_startyear', 'int');
+ $param.='&date_stopday='.GETPOST('date_stopday', 'int');
+ $param.='&date_stopmonth='.GETPOST('date_stopmonth', 'int');
+ $param.='&date_stopyear='.GETPOST('date_stopyear', 'int');
+ print ''."\n\t\t\n\t\t\n\t\t\t";
+ echo dol_print_date($date_start, 'day')." - ".dol_print_date($date_stop, 'day');
+ print '';
+ print '';
+
+ //print '';
+ //print '';
+ //print '';
+
+ //print '';
+ //print '';
+ //print '';
+
+ print '';
+ print ''."\n";
+
+ print ' ';
+
+ print ''; // You can use div-table-responsive-no-min if you dont need reserved height for your table
+ print ' ';
+ print '';
+ print_liste_field_titre($arrayfields['date']['label'], $_SERVER["PHP_SELF"], "date", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
+ print '| '.$langs->trans("Type").' | ';
+ print ''.$langs->trans("Ref").' | ';
+ print ''.$langs->trans("Link").' | ';
+ print ''.$langs->trans("Paid").' | ';
+ print ''.$langs->trans("Debit").' | ';
+ print ''.$langs->trans("Credit").' | ';
+ print ''.$langs->trans("Balance").' | ';
+ print ' ';
+ if ($result)
+ {
+ $TData = dol_sort_array($filesarray, 'date', 'ASC');
+
+ if (empty($TData))
+ {
+ print '| '.$langs->trans("NoItem").' | ';
+ }
+ else
+ {
+ // Sort array by date ASC to calculate balance
+
+ $totalDebit = 0;
+ $totalCredit = 0;
+ // Balance calculation
+ $balance = 0;
+ foreach($TData as &$data1) {
+ if ($data1['item']!='Invoice'&& $data1['item']!='Donation' ){
+ $data1['amount']=-$data1['amount'];
+ }
+ if ($data1['amount']>0){
+ }else{
+ }
+ $balance += $data1['amount'];
+ $data1['balance'] = $balance;
+ }
+
+ // Display array
+ foreach($TData as $data)
+ {
+ $html_class = '';
+ //if (!empty($data['fk_facture'])) $html_class = 'facid-'.$data['fk_facture'];
+ //elseif (!empty($data['fk_paiement'])) $html_class = 'payid-'.$data['fk_paiement'];
+ print '';
+ print "| ";
+ print dol_print_date($data['date'], 'day');
+ print " | \n";
+ print ''.$langs->trans($data['item']).' | ';
+ print ''.$data['ref'].' | ';
+
+ // File link
+ print '".$data['name']." | \n";
+
+ print ''.$data['paid'].' | ';
+ print ''.(($data['amount'] > 0) ? price(abs($data['amount'])) : '')." | \n";
+ $totalDebit += ($data['amount'] > 0) ? abs($data['amount']) : 0;
+ print ''.(($data['amount'] > 0) ? '' : price(abs($data['amount'])))." | \n";
+ $totalCredit += ($data['amount'] > 0) ? 0 : abs($data['amount']);
+ // Balance
+ print ''.price($data['balance'])." | \n";
+ print " \n";
+ }
+
+ print '';
+ print '| | ';
+ print ''.price($totalDebit).' | ';
+ print ''.price($totalCredit).' | ';
+ print ''.price(price2num($totalDebit - $totalCredit, 'MT')).' | ';
+ print " \n";
+ }
+ }
+ print " ";
+ print ' ';
+}
llxFooter();
|