From 5a2161ad09de371fa6a1b36a27a1396b6ce656be Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Feb 2019 19:47:46 +0100 Subject: [PATCH 1/8] Debug export of zip --- htdocs/compta/compta-files.php | 525 ++++++++++++++++++++------------- 1 file changed, 322 insertions(+), 203 deletions(-) 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\t"; -print ''.$langs->trans("dateStart").': '.$form->select_date($date_start,'date_start',0,0,0,"",1,1,1)."\n"; -print ''.$langs->trans("dateStop").': '.$form->select_date($date_stop,'date_stop',0,0,0,"",1,1,1)."\n"; -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 ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -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 ''."\n"; +print ''; +print $langs->trans("ReportPeriod").': '.$form->selectDate($date_start, 'date_start', 0, 0, 0, "", 1, 1, 0); +print ' - '.$form->selectDate($date_stop, 'date_stop', 0, 0, 0, "", 1, 1, 0)."\n"; +// Multicompany +if (! empty($conf->multicompany->enabled) && is_object($mc)) { - $TData = dol_sort_array($filesarray, 'date', 'ASC'); - if(empty($TData)) { - print ''; - } else { - // Sort array by date ASC to calucalte 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 "\n"; - print ''; - print ''; - print '\n"; - print ''; - print '\n"; - $totalDebit += ($data['amount'] > 0) ? abs($data['amount']) : 0; - print '\n"; - $totalCredit += ($data['amount'] > 0) ? 0 : abs($data['amount']); - // Balance - print '\n"; - print "\n"; - } - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } + print '
'; + // This is now done with hook formObjectOptions. Keep this code for backward compatibility with old multicompany module + if (method_exists($mc, 'formObjectOptions')) + { + if (empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && ! $user->entity) // condition must be same for create and edit mode + { + print "".''; + print "\n"; } -print "
'.$langs->trans("Type").''.$langs->trans("Ref").''.$langs->trans("File").''.$langs->trans("Paid").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("Balance").'
'.$langs->trans("NoItem").'
"; - print dol_print_date($data['date'],'day'); - print "'.$data['item'].''.$data['ref'].' ".$data['name']."'.$data['paid'].''.(($data['amount'] > 0) ? price(abs($data['amount'])) : '')."'.(($data['amount'] > 0) ? '' : price(abs($data['amount'])))."'.price($data['balance'])."
 '.price($totalDebit).''.price($totalCredit).''.price(price2num($totalDebit - $totalCredit, 'MT')).'
'.$langs->trans("Entity").'".$mc->select_entities($entity); + print "
"; -print ''."\n\t\t\t"; + else + { + print ''; + } + } -print ''; -print ''; + /*$object = new stdClass(); + // Other attributes + $parameters=array('objectsrc' => null, 'colspan' => ' colspan="3"'); + $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (empty($reshook)) + { + print $object->showOptionals($extrafields, 'edit'); + }*/ +} +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"; + print ''; -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 ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + if ($result) + { + $TData = dol_sort_array($filesarray, 'date', 'ASC'); + + if (empty($TData)) + { + print ''; + } + 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 "\n"; + print ''; + print ''; + + // File link + print '\n"; + + print ''; + print '\n"; + $totalDebit += ($data['amount'] > 0) ? abs($data['amount']) : 0; + print '\n"; + $totalCredit += ($data['amount'] > 0) ? 0 : abs($data['amount']); + // Balance + print '\n"; + print "\n"; + } + + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + } + print "
'.$langs->trans("Type").''.$langs->trans("Ref").''.$langs->trans("Link").''.$langs->trans("Paid").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("Balance").'
'.$langs->trans("NoItem").'
"; + print dol_print_date($data['date'], 'day'); + print "'.$langs->trans($data['item']).''.$data['ref'].'".$data['name']."'.$data['paid'].''.(($data['amount'] > 0) ? price(abs($data['amount'])) : '')."'.(($data['amount'] > 0) ? '' : price(abs($data['amount'])))."'.price($data['balance'])."
 '.price($totalDebit).''.price($totalCredit).''.price(price2num($totalDebit - $totalCredit, 'MT')).'
"; + print '
'; +} llxFooter(); From 036dc52170f96f892baaaa488076ef2bb82a213a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Feb 2019 19:55:54 +0100 Subject: [PATCH 2/8] Fix test --- htdocs/compta/compta-files.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/htdocs/compta/compta-files.php b/htdocs/compta/compta-files.php index 61b05f81e37..1411c52591e 100644 --- a/htdocs/compta/compta-files.php +++ b/htdocs/compta/compta-files.php @@ -70,7 +70,7 @@ $arrayfields=array( ); // Security check -if (empty($conf->compta->enabled) && empty($conf->accounting->enabled)) { +if (empty($conf->comptabilite->enabled) && empty($conf->accounting->enabled)) { accessforbidden(); } if ($user->societe_id > 0) @@ -231,8 +231,8 @@ if(($action=="searchfiles"||$action=="dl" ) && $date_start && $date_stop){ */ //FIXME /* -*ZIP creation -*/ + *ZIP creation + */ if ($result && $action == "dl") { @@ -247,8 +247,8 @@ if ($result && $action == "dl") { 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"; + 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(); @@ -309,14 +309,14 @@ if (! empty($conf->multicompany->enabled) && is_object($mc)) } /*$object = new stdClass(); - // Other attributes - $parameters=array('objectsrc' => null, 'colspan' => ' colspan="3"'); - $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - if (empty($reshook)) - { - print $object->showOptionals($extrafields, 'edit'); - }*/ + // Other attributes + $parameters=array('objectsrc' => null, 'colspan' => ' colspan="3"'); + $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (empty($reshook)) + { + print $object->showOptionals($extrafields, 'edit'); + }*/ } print ''."\n"; From d42bf54436a082992044e7edb798873d143e510b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Feb 2019 23:12:33 +0100 Subject: [PATCH 3/8] Fix export zip --- htdocs/compta/compta-files.php | 69 ++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/htdocs/compta/compta-files.php b/htdocs/compta/compta-files.php index 1411c52591e..33f8b2dcb96 100644 --- a/htdocs/compta/compta-files.php +++ b/htdocs/compta/compta-files.php @@ -236,10 +236,14 @@ if(($action=="searchfiles"||$action=="dl" ) && $date_start && $date_stop){ if ($result && $action == "dl") { - dol_delete_file($zip); + $dirfortmpfile = ($conf->accounting->dir_temp ? $conf->accounting->dir_temp : $conf->compta->dir_temp); + + dol_mkdir($dirfortmpfile); $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'; + $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc')."-".dol_print_date($date_stop, 'dayrfc').'_export.zip'; + + dol_delete_file(name); $zip = new ZipArchive; $res = $zip->open($zipname, ZipArchive::OVERWRITE|ZipArchive::CREATE); @@ -248,7 +252,7 @@ if ($result && $action == "dl") 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"; + $log.=dol_print_date($file['date'], 'dayrfc').','.$file['item'].','.$file['ref'].','.$file['amount'].','.$file['paid'].','.$file["name"].','.$file['fk']."\n"; } $zip->addFromString('transactions.csv', $log); $zip->close(); @@ -290,34 +294,43 @@ print ''; print $langs->trans("ReportPeriod").': '.$form->selectDate($date_start, 'date_start', 0, 0, 0, "", 1, 1, 0); print ' - '.$form->selectDate($date_stop, 'date_stop', 0, 0, 0, "", 1, 1, 0)."\n"; // Multicompany +/*if (! empty($conf->multicompany->enabled) && is_object($mc)) + { + print '
'; + // This is now done with hook formObjectOptions. Keep this code for backward compatibility with old multicompany module + if (method_exists($mc, 'formObjectOptions')) + { + if (empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && ! $user->entity) // condition must be same for create and edit mode + { + print "".''.$langs->trans("Entity").''; + print "".$mc->select_entities($entity); + print "\n"; + } + else + { + print ''; + } + } + + $object = new stdClass(); + // Other attributes + $parameters=array('objectsrc' => null, 'colspan' => ' colspan="3"'); + $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (empty($reshook)) + { + print $object->showOptionals($extrafields, 'edit'); + } + }*/ if (! empty($conf->multicompany->enabled) && is_object($mc)) { - print '
'; - // This is now done with hook formObjectOptions. Keep this code for backward compatibility with old multicompany module - if (method_exists($mc, 'formObjectOptions')) - { - if (empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && ! $user->entity) // condition must be same for create and edit mode - { - print "".''.$langs->trans("Entity").''; - print "".$mc->select_entities($entity); - print "\n"; - } - else - { - print ''; - } - } - - /*$object = new stdClass(); - // Other attributes - $parameters=array('objectsrc' => null, 'colspan' => ' colspan="3"'); - $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - if (empty($reshook)) - { - print $object->showOptionals($extrafields, 'edit'); - }*/ + print '   -   '.$langs->trans("Entity").' : '; + $mc->dao->getEntities(); + $mc->dao->fetch($conf->entity); + print $mc->dao->label; + print "
\n"; } + print ''."\n"; dol_fiche_end(); From 639dfa09aa6e7c743685b55e7244dddd345511a6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Feb 2019 23:17:40 +0100 Subject: [PATCH 4/8] Fix creation of left menu --- htdocs/admin/menus/edit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php index 33a73147251..35707360e60 100644 --- a/htdocs/admin/menus/edit.php +++ b/htdocs/admin/menus/edit.php @@ -214,9 +214,9 @@ if ($action == 'add') $menu->target=GETPOST('target','alpha'); $menu->user=GETPOST('user','alpha'); $menu->mainmenu=GETPOST('propertymainmenu','alpha'); - if (is_numeric(GETPOST('menuId','int'))) + if (is_numeric(GETPOST('menuId','alpha'))) { - $menu->fk_menu=GETPOST('menuId','int'); + $menu->fk_menu=GETPOST('menuId','alpha'); } else { From d86017b8ff55c09d5c932c229b413e6acae43774 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Feb 2019 23:21:53 +0100 Subject: [PATCH 5/8] Fix create left menu entry --- htdocs/admin/menus/edit.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php index 35707360e60..fde40ecdca5 100644 --- a/htdocs/admin/menus/edit.php +++ b/htdocs/admin/menus/edit.php @@ -144,6 +144,22 @@ if ($action == 'add') } $leftmenu=''; $mainmenu=''; + if (! empty($_POST['menuId']) && ! is_numeric($_POST['menuId'])) + { + $tmp=explode('&',$_POST['menuId']); + foreach($tmp as $s) + { + if (preg_match('/fk_mainmenu=/',$s)) + { + $mainmenu=preg_replace('/fk_mainmenu=/','',$s); + } + if (preg_match('/fk_leftmenu=/',$s)) + { + $leftmenu=preg_replace('/fk_leftmenu=/','',$s); + } + } + } + if (GETPOST('menuId', 'alpha') && ! is_numeric(GETPOST('menuId', 'alpha'))) { $tmp=explode('&', GETPOST('menuId', 'alpha')); From 11f48460b2c3912acfd2c0cbc7b6ace47ed39460 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Feb 2019 23:26:25 +0100 Subject: [PATCH 6/8] Fix --- htdocs/admin/menus/edit.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php index fde40ecdca5..35707360e60 100644 --- a/htdocs/admin/menus/edit.php +++ b/htdocs/admin/menus/edit.php @@ -144,22 +144,6 @@ if ($action == 'add') } $leftmenu=''; $mainmenu=''; - if (! empty($_POST['menuId']) && ! is_numeric($_POST['menuId'])) - { - $tmp=explode('&',$_POST['menuId']); - foreach($tmp as $s) - { - if (preg_match('/fk_mainmenu=/',$s)) - { - $mainmenu=preg_replace('/fk_mainmenu=/','',$s); - } - if (preg_match('/fk_leftmenu=/',$s)) - { - $leftmenu=preg_replace('/fk_leftmenu=/','',$s); - } - } - } - if (GETPOST('menuId', 'alpha') && ! is_numeric(GETPOST('menuId', 'alpha'))) { $tmp=explode('&', GETPOST('menuId', 'alpha')); From ced386fdca5f7e84f2c9b174d4e77bd8b463fe14 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 13 Feb 2019 11:32:00 +0100 Subject: [PATCH 7/8] Fix phpcs --- .../core/class/commondocgenerator.class.php | 10 +- htdocs/margin/agentMargins.php | 10 +- htdocs/product/stock/movement_card.php | 136 +++++++++--------- htdocs/projet/tasks/time.php | 4 +- .../class/html.formresource.class.php | 2 +- 5 files changed, 81 insertions(+), 81 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 235dde63096..98d7e720628 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -488,10 +488,10 @@ abstract class CommonDocGenerator if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0; $resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva; $resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]); - + $totalUp += $line->subprice * $line->qty; } - + // @GS: Calculate total up and total discount percentage // Note that this added fields correspond to nothing in Dolibarr (Dolibarr manage discount on lines not globally) $resarray['object_total_up'] = $totalUp; @@ -501,7 +501,7 @@ abstract class CommonDocGenerator $resarray['object_total_discount_locale'] = price($resarray['object_total_discount'], 0, $outputlangs); } } - + // Retrieve extrafields if (is_array($object->array_options) && count($object->array_options)) { @@ -514,7 +514,7 @@ abstract class CommonDocGenerator $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs); } - + return $resarray; } @@ -585,7 +585,7 @@ abstract class CommonDocGenerator $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true); $line->fetch_optionals(); - $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key=$array_key, $outputlangs); + $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs); // Load product data optional fields to the line -> enables to use "line_options_{extrafield}" if (isset($line->fk_product) && $line->fk_product > 0) diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index 8bdbaac5861..197c912494a 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -212,13 +212,13 @@ if ($result) else print_liste_field_titre("SalesRepresentative", $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"], "selling_price", "", $param, 'align="right"', $sortfield, $sortorder); - print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"], "buying_price", "", $param,' align="right"', $sortfield, $sortorder); - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"], "marge", "", $param, 'align="right"', $sortfield, $sortorder); + print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", $param, 'align="right"', $sortfield, $sortorder); + print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", $param,' align="right"', $sortfield, $sortorder); + print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", $param, 'align="right"', $sortfield, $sortorder); if (! empty($conf->global->DISPLAY_MARGIN_RATES)) - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"], "", "", $param, 'align="right"', $sortfield, $sortorder); + print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", $param, 'align="right"', $sortfield, $sortorder); if (! empty($conf->global->DISPLAY_MARK_RATES)) - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"], "", "", $param, 'align="right"', $sortfield, $sortorder); + print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", $param, 'align="right"', $sortfield, $sortorder); print "\n"; $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); diff --git a/htdocs/product/stock/movement_card.php b/htdocs/product/stock/movement_card.php index abf7d21284b..fcfa26bb832 100644 --- a/htdocs/product/stock/movement_card.php +++ b/htdocs/product/stock/movement_card.php @@ -49,38 +49,38 @@ if (! empty($conf->productbatch->enabled)) $langs->load("productbatch"); // Security check $result=restrictedArea($user,'stock'); -$id=GETPOST('id','int'); -$ref = GETPOST('ref','alpha'); -$msid=GETPOST('msid','int'); -$product_id=GETPOST("product_id"); -$action=GETPOST('action','aZ09'); -$cancel=GETPOST('cancel','alpha'); -$contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'movementlist'; +$id=GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); +$msid=GETPOST('msid', 'int'); +$product_id=GETPOST("product_id", 'int'); +$action=GETPOST('action', 'aZ09'); +$cancel=GETPOST('cancel', 'alpha'); +$contextpage=GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'movementlist'; -$idproduct = GETPOST('idproduct','int'); -$year = GETPOST("year"); -$month = GETPOST("month"); +$idproduct = GETPOST('idproduct', 'int'); +$year = GETPOST("year", 'int'); +$month = GETPOST("month", 'int'); $search_ref = GETPOST('search_ref', 'alpha'); -$search_movement = GETPOST("search_movement"); -$search_product_ref = trim(GETPOST("search_product_ref")); -$search_product = trim(GETPOST("search_product")); -$search_warehouse = trim(GETPOST("search_warehouse")); -$search_inventorycode = trim(GETPOST("search_inventorycode")); -$search_user = trim(GETPOST("search_user")); -$search_batch = trim(GETPOST("search_batch")); -$search_qty = trim(GETPOST("search_qty")); +$search_movement = GETPOST("search_movement", 'alpha'); +$search_product_ref = trim(GETPOST("search_product_ref", 'alpha')); +$search_product = trim(GETPOST("search_product", 'alpha')); +$search_warehouse = trim(GETPOST("search_warehouse", 'alpha')); +$search_inventorycode = trim(GETPOST("search_inventorycode", 'alpha')); +$search_user = trim(GETPOST("search_user", 'alpha')); +$search_batch = trim(GETPOST("search_batch", 'alpha')); +$search_qty = trim(GETPOST("search_qty", 'alpha')); $search_type_mouvement=GETPOST('search_type_mouvement','int'); -$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; -$page = GETPOST("page",'int'); -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); +$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; +$page = GETPOST("page", 'int'); +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; if (! $sortfield) $sortfield="m.datem"; if (! $sortorder) $sortorder="DESC"; -$pdluoid=GETPOST('pdluoid','int'); +$pdluoid=GETPOST('pdluoid', 'int'); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $object = new MouvementStock($db); @@ -90,7 +90,7 @@ $formfile = new FormFile($db); // fetch optionals attributes and labels $extralabels = $extrafields->fetch_name_optionals_label('movement'); -$search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_'); +$search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); $arrayfields=array( 'm.rowid'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), @@ -132,7 +132,7 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Do we click on purge search criteria ? -if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers { $year=''; $month=''; @@ -185,22 +185,22 @@ if ($action == "correct_stock") if ($product->hasbatch()) { - $batch=GETPOST('batch_number'); + $batch=GETPOST('batch_number', 'alpha'); //$eatby=GETPOST('eatby'); //$sellby=GETPOST('sellby'); - $eatby=dol_mktime(0, 0, 0, GETPOST('eatbymonth'), GETPOST('eatbyday'), GETPOST('eatbyyear')); - $sellby=dol_mktime(0, 0, 0, GETPOST('sellbymonth'), GETPOST('sellbyday'), GETPOST('sellbyyear')); + $eatby=dol_mktime(0, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int')); + $sellby=dol_mktime(0, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int')); $result=$product->correct_stock_batch( $user, $id, - GETPOST("nbpiece",'int'), - GETPOST("mouvement"), - GETPOST("label",'san_alpha'), - GETPOST('unitprice'), + GETPOST("nbpiece", 'int'), + GETPOST("mouvement", 'int'), + GETPOST("label", 'san_alpha'), + GETPOST('unitprice', 'alpha'), $eatby,$sellby,$batch, - GETPOST('inventorycode'), + GETPOST('inventorycode', 'alpha'), $origin_element, $origin_id ); // We do not change value of stock for a correction @@ -210,11 +210,11 @@ if ($action == "correct_stock") $result=$product->correct_stock( $user, $id, - GETPOST("nbpiece",'int'), - GETPOST("mouvement"), + GETPOST("nbpiece", 'int'), + GETPOST("mouvement", 'alpha'), GETPOST("label",'san_alpha'), - GETPOST('unitprice'), - GETPOST('inventorycode'), + GETPOST('unitprice', 'alpha'), + GETPOST('inventorycode', 'alpha'), $origin_element, $origin_id ); // We do not change value of stock for a correction @@ -242,7 +242,7 @@ if ($action == "transfert_stock" && ! $cancel) $product = new Product($db); if (! empty($product_id)) $result=$product->fetch($product_id); - if (! (GETPOST("id_entrepot_destination",'int') > 0)) + if (! (GETPOST("id_entrepot_destination", 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $error++; @@ -272,7 +272,7 @@ if ($action == "transfert_stock" && ! $cancel) $product = new Product($db); $result=$product->fetch($product_id); - if ($product->hasbatch() && ! GETPOST("batch_number")) + if ($product->hasbatch() && ! GETPOST("batch_number", 'alpha')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors'); $error++; @@ -319,7 +319,7 @@ if ($action == "transfert_stock" && ! $cancel) else { $srcwarehouseid=$id; - $batch=GETPOST('batch_number'); + $batch=GETPOST('batch_number', 'alpha'); $eatby=$d_eatby; $sellby=$d_sellby; } @@ -330,23 +330,23 @@ if ($action == "transfert_stock" && ! $cancel) $result1=$product->correct_stock_batch( $user, $srcwarehouseid, - GETPOST("nbpiece",'int'), + GETPOST("nbpiece", 'int'), 1, - GETPOST("label",'san_alpha'), + GETPOST("label", 'san_alpha'), $pricesrc, $eatby,$sellby,$batch, - GETPOST('inventorycode') + GETPOST('inventorycode', 'alpha') ); // Add stock $result2=$product->correct_stock_batch( $user, - GETPOST("id_entrepot_destination",'int'), - GETPOST("nbpiece",'int'), + GETPOST("id_entrepot_destination", 'int'), + GETPOST("nbpiece", 'int'), 0, - GETPOST("label",'san_alpha'), + GETPOST("label", 'san_alpha'), $pricedest, $eatby,$sellby,$batch, - GETPOST('inventorycode') + GETPOST('inventorycode', 'alpha') ); } } @@ -356,22 +356,22 @@ if ($action == "transfert_stock" && ! $cancel) $result1=$product->correct_stock( $user, $id, - GETPOST("nbpiece"), + GETPOST("nbpiece", 'int'), 1, - GETPOST("label"), + GETPOST("label", 'alpha'), $pricesrc, - GETPOST('inventorycode') + GETPOST('inventorycode', 'alpha') ); // Add stock $result2=$product->correct_stock( $user, GETPOST("id_entrepot_destination"), - GETPOST("nbpiece"), + GETPOST("nbpiece", 'int'), 0, - GETPOST("label"), + GETPOST("label", 'alpha'), $pricedest, - GETPOST('inventorycode') + GETPOST('inventorycode', 'alpha') ); } if (! $error && $result1 >= 0 && $result2 >= 0) @@ -568,7 +568,7 @@ if ($resql) $morehtmlref.=''; $shownav = 1; - if ($user->societe_id && ! in_array('stock', explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; + if ($user->societe_id && ! in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref); @@ -693,9 +693,9 @@ if ($resql) } $param=''; - if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - if ($id > 0) $param.='&id='.$id; + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); + if ($id > 0) $param.='&id='.urlencode($id); if ($search_movement) $param.='&search_movement='.urlencode($search_movement); if ($search_inventorycode) $param.='&search_inventorycode='.urlencode($search_inventorycode); if ($search_type_mouvement) $param.='&search_type_mouvement='.urlencode($search_type_mouvement); @@ -706,7 +706,7 @@ if ($resql) if (!empty($sref)) $param.='&sref='.urlencode($sref); // FIXME $sref is not defined if (!empty($snom)) $param.='&snom='.urlencode($snom); // FIXME $snom is not defined if ($search_user) $param.='&search_user='.urlencode($search_user); - if ($idproduct > 0) $param.='&idproduct='.$idproduct; + if ($idproduct > 0) $param.='&idproduct='.urlencode($idproduct); // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -737,7 +737,7 @@ if ($resql) if ($sall) { foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); - print '
'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'
'; + print '
'.$langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall).'
'; } $moreforfilter=''; @@ -928,9 +928,9 @@ if ($resql) $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder); $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (! empty($arrayfields['m.datec']['checked'])) print_liste_field_titre($arrayfields['p.datec']['label'],$_SERVER["PHP_SELF"],"p.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); - if (! empty($arrayfields['m.tms']['checked'])) print_liste_field_titre($arrayfields['p.tms']['label'],$_SERVER["PHP_SELF"],"p.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); - print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch '); + if (! empty($arrayfields['m.datec']['checked'])) print_liste_field_titre($arrayfields['p.datec']['label'] ,$_SERVER["PHP_SELF"], "p.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); + if (! empty($arrayfields['m.tms']['checked'])) print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); print "\n"; @@ -978,7 +978,7 @@ if ($resql) if (! empty($arrayfields['m.datem']['checked'])) { // Date - print ''.dol_print_date($db->jdate($objp->datem),'dayhour').''; + print ''.dol_print_date($db->jdate($objp->datem), 'dayhour').''; } if (! empty($arrayfields['p.ref']['checked'])) { @@ -1007,11 +1007,11 @@ if ($resql) } if (! empty($arrayfields['pl.eatby']['checked'])) { - print ''. dol_print_date($objp->eatby,'day') .''; + print ''. dol_print_date($objp->eatby, 'day') .''; } if (! empty($arrayfields['pl.sellby']['checked'])) { - print ''. dol_print_date($objp->sellby,'day') .''; + print ''. dol_print_date($objp->sellby, 'day') .''; } // Warehouse if (! empty($arrayfields['e.ref']['checked'])) @@ -1120,14 +1120,14 @@ if ($resql) $balanceafter=$movement->calculateBalanceForProductBefore($productidselected, $dateafter); //print ''; - print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore,'day','gmt')); + print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore, 'day', 'gmt')); //print ''; //print ''; print ': '.$balancebefore; print "
\n"; //print ''; //print ''; - print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter,'day','gmt')); + print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter, 'day', 'gmt')); //print ''; //print ''; print ': '.$balanceafter; @@ -1169,7 +1169,7 @@ if ($action != 'create' && $action != 'edit' && $action != 'delete' && $id>0) $genallowed=$user->rights->stock->lire; $delallowed=$user->rights->stock->creer; - print $formfile->showdocuments($modulepart,$objectref,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang, '', $object); + print $formfile->showdocuments($modulepart, $objectref, $filedir, $urlsource, $genallowed, $delallowed, '', 0, 0, 0, 28, 0, '', 0, '', $object->default_lang, '', $object); $somethingshown=$formfile->numoffiles; print '
'; diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index be87a52fcd9..1f09d7e9a77 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -1045,8 +1045,8 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) $contactsofproject=$projectstatic->getListContactId('internal'); if (count($contactsofproject)>0) { - if (in_array($user->id, $userid=$contactsofproject)) $userid = $user->id; - else $userid=$contactsofproject[0]; + if (in_array($user->id, $contactsofproject)) $userid = $user->id; + else $userid = $contactsofproject[0]; if ($projectstatic->public) $contactsofproject = array(); print $form->select_dolusers((GETPOST('userid')?GETPOST('userid'):$userid), 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, $langs->trans("ResourceNotAssignedToProject"), 'maxwidth200'); } diff --git a/htdocs/resource/class/html.formresource.class.php b/htdocs/resource/class/html.formresource.class.php index 39b789c2b7d..e4cc5a64ab7 100644 --- a/htdocs/resource/class/html.formresource.class.php +++ b/htdocs/resource/class/html.formresource.class.php @@ -85,7 +85,7 @@ class FormResource $resourcestat = new Dolresource($this->db); - $resources_used = $resourcestat->fetch_all('ASC', 't.rowid', $limit, $offset, $filter=''); + $resources_used = $resourcestat->fetch_all('ASC', 't.rowid', $limit, $offset, $filter); if ($outputmode != 2) { From 04e3f2347606f9fd0b33c01c20822ba32694b641 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 13 Feb 2019 11:52:45 +0100 Subject: [PATCH 8/8] Fix phpcs --- htdocs/compta/compta-files.php | 2 +- htdocs/margin/agentMargins.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/compta-files.php b/htdocs/compta/compta-files.php index cb49b35d242..665b9ba63de 100644 --- a/htdocs/compta/compta-files.php +++ b/htdocs/compta/compta-files.php @@ -82,7 +82,7 @@ if ($user->societe_id > 0) * Actions */ -$entity = GETPOST('entity','int')?GETPOST('entity','int'):$conf->entity; +$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 diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index 197c912494a..8f6c03d5623 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -213,7 +213,7 @@ if ($result) print_liste_field_titre("SalesRepresentative", $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", $param, 'align="right"', $sortfield, $sortorder); - print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", $param,' align="right"', $sortfield, $sortorder); + print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", $param, 'align="right"', $sortfield, $sortorder); print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", $param, 'align="right"', $sortfield, $sortorder); if (! empty($conf->global->DISPLAY_MARGIN_RATES)) print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", $param, 'align="right"', $sortfield, $sortorder); @@ -225,8 +225,6 @@ if ($result) if ($num > 0) { - $var=true; - $group_list = array(); while ($objp = $db->fetch_object($result)) { if ($agentid > 0) {