diff --git a/ChangeLog b/ChangeLog index ffb944785e2..6a738760f86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,7 +7,9 @@ For users: - New: [ task #877 ] Reorganize some menus. - New: [ task #858 ] Holiday module: note on manual holiday assignation. - New: Add graph of bank account input/output into input-output report page. - +- New: Add script export-bank-receipts. +- New: Add option "filter=bank" onto script rebuild_merge_pdf.php to merge + PDF that has one payment on a specific bank account. For developers: - New: DolGraph can build graph with three lines. @@ -101,32 +103,32 @@ WARNING: If you used external modules, some of them may need to be upgraded due ***** ChangeLog for 3.3.2 compared to 3.3.1 ***** -- Fix: Dutch (nl_NL) translation -- Generalize fix: file with a specific mask not found, again -- Fix: translations and BILL_SUPPLIER_BUILDDOC trigger -- Fix: Can't reset payment due date -- Fix: Orderstoinvoice didn't act as expected when no order was checked -- Fix: Bad link to all proposals into Third party card if customer is prospect -- Fix: Some bugs on withdrawal rejects -- Fix: [ bug #774 ] Bug on creating event with box "all day" crossed -- Fix: [ bug #787 ] Invoice supplier box incorrect tooltip when delay on payment -- Fix: [ bug #789 ] VAT not being calculated in POS -- Fix: [ bug #790 ] Spanish localtax RE not being correctly calculated -- Fix: [ bug #794 ] Lost filter on zipcode in prospect list -- Fix: [ bug #806 ] Margins module with orders2invoice does not respect cost price -- Fix: [ bug #810 ] Cannot update ODT template path -- Fix: [ bug #816 ] Sales journal does not reflect localtaxes -- Fix: [ bug #817 ] Purchases journal does not reflect localtaxes -- Fix: [ bug #824 ] MAIN_DB_PREFIX not use into dictionnary -- Fix: [ bug #828 ] Error when code_region is not a number in llx_c_regions (with postgres) -- Fix: [ bug #855 ] Holiday approval email in French -- Fix: [ bug #856 ] (Holidays module) Mail error if destination user doesn't have an email -- Fix: [ bug #857 ] Invoice created from shipment does not have the order discount -- Fix: [ bug #861 ] Impossible to create a new event in agenda -- Fix: [ bug #827 ] AJAX search does not respect multiprice level -- Fix: [ bug #865 ] Dolibarr navigation array in project/task do not work -- Fix: [ bug #866 ] Standing order from an invoice suggests invoice total amount instead of remaining to pay -- Fix: [ bug #788 ] Date of linked interventions are not shown +- Fix: Dutch (nl_NL) translation. +- Generalize fix: file with a specific mask not found, again. +- Fix: translations and BILL_SUPPLIER_BUILDDOC trigger. +- Fix: Can't reset payment due date. +- Fix: Orderstoinvoice didn't act as expected when no order was checked. +- Fix: Bad link to all proposals into Third party card if customer is prospect. +- Fix: Some bugs on withdrawal rejects. +- Fix: [ bug #774 ] Bug on creating event with box "all day" crossed. +- Fix: [ bug #787 ] Invoice supplier box incorrect tooltip when delay on payment. +- Fix: [ bug #789 ] VAT not being calculated in POS. +- Fix: [ bug #790 ] Spanish localtax RE not being correctly calculated. +- Fix: [ bug #794 ] Lost filter on zipcode in prospect list. +- Fix: [ bug #806 ] Margins module with orders2invoice does not respect cost price. +- Fix: [ bug #810 ] Cannot update ODT template path. +- Fix: [ bug #816 ] Sales journal does not reflect localtaxes. +- Fix: [ bug #817 ] Purchases journal does not reflect localtaxes. +- Fix: [ bug #824 ] MAIN_DB_PREFIX not use into dictionnary. +- Fix: [ bug #828 ] Error when code_region is not a number in llx_c_regions (with postgres). +- Fix: [ bug #855 ] Holiday approval email in French. +- Fix: [ bug #856 ] (Holidays module) Mail error if destination user doesn't have an email. +- Fix: [ bug #857 ] Invoice created from shipment does not have the order discount. +- Fix: [ bug #861 ] Impossible to create a new event in agenda. +- Fix: [ bug #827 ] AJAX search does not respect multiprice level. +- Fix: [ bug #865 ] Dolibarr navigation array in project/task do not work. +- Fix: [ bug #866 ] Standing order from an invoice suggests invoice total amount instead of remaining to pay. +- Fix: [ bug #788 ] Date of linked interventions are not shown. ***** ChangeLog for 3.3.1 compared to 3.3 ***** diff --git a/README-FR b/README-FR index ac3a9ae2d8c..cc69cfa6e8a 100644 --- a/README-FR +++ b/README-FR @@ -78,30 +78,29 @@ IV - CE QUE DOLIBARR PEUT FAIRE ------------------------------- Modules principaux: +- Annuaires des prospects et/ou client et/ou fournisseurs - Gestion de catalogue de produits et services - Gestion de stock - Gestion des comptes bancaires -- Annuaires des prospects et/ou client et/ou fournisseurs -- Annuaires des contacts -- Gestion des actions/taches avec un agenda intégré (ou lien avec webcalendar) +- Agenda partagé - Gestion des commandes -- Gestion des propositions commerciales -- Gestion de contrats de services +- Gestion des devis, propositions commerciales - Gestion des factures clients et fournisseurs +- Gestion de contrats de services - Gestion des paiements - Gestion des virements bancaires - Gestion des expéditions +- GED (Gestion Electronique de Documents) +- EMailings de masse +- Réalisation de sondages +- Point de vente/Caisse enregistreuse Autres modules: -- Gestion de la TVA NPR (non perçue récupérable - pour les utilisateurs français des DOM-TOM) -- Gestion des adhérents d'association -- Gestion des dons - Gestion de marque-pages -- Agenda -- Point de vente/Caisse enregistreuse -- Fonctions d'EMailing de masses vers les clients, prospect ou utilisateurs Dolibarr +- Gestion des promesses de dons +- Gestion de la TVA NPR (non perçue récupérable - pour les utilisateurs français des DOM-TOM) - Rapports -- Fonctions d'exports +- Imports/Exports des données - Connectivité LDAP - Export PDF de tous les éléments (factures, propositions commerciales, commandes, bons expéditions, etc...) - De nombreuses autres fonctionnalités issues de modules officiels ou non (AWStats, Bittorrent, Gravatar, Google, Webcalendar...) @@ -122,7 +121,7 @@ V - CE QUE DOLIBARR NE PEUT PAS FAIRE (TACHES A FAIRE) Voici un liste de fonctionnalites pas encore gérées par Dolibarr: - Pas de compta analytique (uniquement gestion de trésorerie). - Dolibarr ne gère qu'une seule monnaie à la fois (mono-devise). -- Dolibarr ne gère en standard qu'une société/institution/association (mono-société). Pour en gérer plusieurs (comme vos filiales), il faut, soit faire plusieurs installations de Dolibarr, soit installer le module MultiCompany qui permet de gérer n société/institutions/associations dans une seule instance par une isolation logique des données. +- Dolibarr ne gère en standard qu'une société/institution/association mère (mono-société). Pour en gérer plusieurs (comme vos filiales), il faut, soit faire plusieurs installations de Dolibarr, soit installer le module MultiCompany qui permet de gérer n société/institutions/associations dans une seule instance par une isolation logique des données. - Ne gère pas la double tva (Fédérale / provinciale) du canada. - Dolibarr ne contient pas de module de Gestion de la paie. - Les taches du module de gestion de projets n'ont pas de dépendance entre elle. diff --git a/README.md b/README.md index e3d86854a70..257d19e60fb 100644 --- a/README.md +++ b/README.md @@ -75,33 +75,35 @@ See ChangeLog file found into package. ### Main modules/features: -- Products and services catalog - Customers, Prospects or Suppliers directory -- Address book +- Products and services catalog - Stock management - Bank accounts management - Orders management with PDF export -- Commercial proposals management with PDF export +- Commercial proposals management - Contracts management -- Invoices management with PDF export +- Invoices management - Payments management - Standing orders management - Shipping management -- ECM (Electronic Content Management) -- EMailings - Agenda with ical,vcal export for third tools integration -- Management of foundation members -- Donation management +- ECM (Electronic Content Management) +- Foundations members management +- Employee's holidays management +- Mass emailing +- Realize surveys +- Point of Sale ### Other modules: - Bookmarks management -- Can reports Dolibarr events inside Webcalendar or Phenix -- Data export tools +- Donations management +- Reporting +- Data export/import tools - LDAP connectivity - Third parties or products categories - ClickToDial phone numbers -- RSS +- RSS integration ### Miscellaneous: @@ -123,11 +125,11 @@ See ChangeLog file found into package. This is features that Dolibarr does not support completely yet: -- No accountancy (only bank management). +- No double party accountancy (only bank management). - Dolibarr manage one currency at once (mono-currency). -- Dolibarr manage one company/foundation (mono-company). If you want to manage several companies or foundations, you must install several time the software (on same server or not). Another solution is to extend Dolibarr with the addon Module MultiCompany that allows to manage several companies in one Dolibarr instance (one database but with a logical isolation of datas). +- Dolibarr manage one master company/foundation (mono-company). If you want to manage several companies or foundations, you must install several time the software (on same server or not). Another solution is to extend Dolibarr with the addon Module MultiCompany that allows to manage several companies in one Dolibarr instance (one database but with a logical isolation of datas). - Does not support double VAT (Federal / provincial) for Canada. - Dolibarr does not contains Payroll module. - Tasks on module project can't have dependencies between each other. - Dolibarr does not include any Webmail. -- Dolibarr can't do coffee (not yet). \ No newline at end of file +- Dolibarr can't do coffee (not yet). diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 0390efcdda4..3733973bb2a 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -68,7 +68,6 @@ if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL' $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", '','chaine',0,'',$conf->entity); $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", '','chaine',0,'',$conf->entity); $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", '','chaine',0,'',$conf->entity); - $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_DELETE_INVOICE", '','chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_BILL','alpha'),'chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER','alpha'),'chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha'),'chaine',0,'',$conf->entity); @@ -241,19 +240,6 @@ if (! empty($conf->fournisseur->enabled)) print ''; print "\n\n\n"; } -if (! empty($conf->facture->enabled)) -{ - $var=!$var; - print ""; - print ''.$langs->trans("ReStockOnDeleteInvoice").''; - print ''; - print "
"; - print ''; - print ""; - print $form->selectyesno("STOCK_CALCULATE_ON_DELETE_INVOICE",$conf->global->STOCK_CALCULATE_ON_DELETE_INVOICE,1); - print ''; - print "
\n\n\n"; -} print ''; diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index f230ba1a95b..8b93bf23590 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -932,7 +932,7 @@ if ($id > 0) // Busy print ''.$langs->trans("Busy").''; - print yn(($act->transparency > 0)?1:0); + if ($act->usertodo->id > 0) print yn(($act->transparency > 0)?1:0); // We show nothing if event is assigned to nobody print ''; // Done by diff --git a/htdocs/compta/bank/annuel.php b/htdocs/compta/bank/annuel.php index 3cda0da6166..a211dcb686d 100644 --- a/htdocs/compta/bank/annuel.php +++ b/htdocs/compta/bank/annuel.php @@ -1,518 +1,518 @@ - - * Copyright (C) 2004-2010 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2013 Charles-Fr BENKE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/compta/bank/annuel.php - * \ingroup banque - * \brief Page to report input-output of a bank account - */ - -require('../../main.inc.php'); -require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; - -$langs->load("banks"); -$langs->load("categories"); - -$id=GETPOST('account'); -$ref=GETPOST('ref'); - -// Security check -$fieldid = (! empty($ref)?$ref:$id); -$fieldname = isset($ref)?'ref':'rowid'; -if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'banque',$fieldid,'bank_account','','',$fieldname); - -$year_start=GETPOST('year_start'); -$year_current = strftime("%Y",time()); -if (! $year_start) -{ - $year_start = $year_current - 2; - $year_end = $year_current; -} -else -{ - $year_end=$year_start+2; -} - - -llxHeader(); - -$form = new Form($db); - -// Get account informations -$acct = new Account($db); -if ($id > 0 && ! preg_match('/,/', $id)) // if for a particular account and not a list -{ - $result=$acct->fetch($id); - $id=$acct->id; -} -if (! empty($ref)) -{ - $result=$acct->fetch(0, $ref); - $id=$acct->id; -} - - -// Ce rapport de tresorerie est base sur llx_bank (car doit inclure les transactions sans facture) -// plutot que sur llx_paiement + llx_paiementfourn - -$sql = "SELECT SUM(b.amount)"; -$sql.= ", date_format(b.dateo,'%Y-%m') as dm"; -$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; -$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; -$sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity = ".$conf->entity; -$sql.= " AND b.amount >= 0"; -if (! empty($id)) - $sql .= " AND b.fk_account IN (".$db->escape($id).")"; -$sql.= " GROUP BY dm"; - -$resql=$db->query($sql); -if ($resql) -{ - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $row = $db->fetch_row($resql); - $encaiss[$row[1]] = $row[0]; - $i++; - } -} -else -{ - dol_print_error($db); -} - -$sql = "SELECT SUM(b.amount)"; -$sql.= ", date_format(b.dateo,'%Y-%m') as dm"; -$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; -$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; -$sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity = ".$conf->entity; -$sql.= " AND b.amount <= 0"; -if (! empty($id)) - $sql .= " AND b.fk_account IN (".$db->escape($id).")"; -$sql.= " GROUP BY dm"; - -$resql=$db->query($sql); -if ($resql) -{ - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $row = $db->fetch_row($resql); - $decaiss[$row[1]] = -$row[0]; - $i++; - } -} -else -{ - dol_print_error($db); -} - - -// Onglets -$head=bank_prepare_head($acct); -dol_fiche_head($head,'annual',$langs->trans("FinancialAccount"),0,'account'); - -$title=$langs->trans("FinancialAccount")." : ".$acct->label; -$lien=($year_start?"".img_previous()." ".$langs->trans("Year")." ".img_next()."":""); - -print ''; - -$linkback = ''.$langs->trans("BackToList").''; - -// Ref -print ''; -print ''; - -// Label -print ''; -print ''; - -print '
'.$langs->trans("Ref").''; -if ($_GET["account"]) -{ - if (! preg_match('/,/', $id)) - { - print $form->showrefnav($acct, 'ref', $linkback, 1, 'ref'); - } - else - { - $bankaccount=new Account($db); - $listid=explode(',', $id); - foreach($listid as $key => $aId) - { - $bankaccount->fetch($aId); - $bankaccount->label=$bankaccount->ref; - print $bankaccount->getNomUrl(1); - if ($key < (count($listid)-1)) print ', '; - } - } -} -else -{ - print $langs->trans("ALL"); -} -print '
'.$langs->trans("Label").''; -if (! empty($id)) -{ - print $acct->label; -} -else -{ - print $langs->trans("AllAccounts"); -} -print '
'; - -print '
'; - -// Affiche tableau -print ''; - -print ''; - -print ''; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) -{ - print ''; -} -print ''; - -print ''; -print ''; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) -{ - print ''; -} -print ''; - -$var=true; -for ($mois = 1 ; $mois < 13 ; $mois++) -{ - $var=!$var; - print ''; - print ""; - for ($annee = $year_start ; $annee <= $year_end ; $annee++) - { - $case = sprintf("%04s-%02s",$annee,$mois); - - print '"; - - print '"; - } - print ''; -} - -// Total debit-credit -print '"; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) -{ - print ''; -} -print "\n"; - -// Ligne vierge -print ''; -$nbcol=0; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) -{ - $nbcol+=2; -} -print "\n"; - -// Solde actuel -$balance=0; - -$sql = "SELECT SUM(b.amount) as total"; -$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; -$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; -$sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity = ".$conf->entity; -if (! empty($id)) - $sql.= " AND b.fk_account IN (".$db->escape($id).")"; - -$resql=$db->query($sql); -if ($resql) -{ - $obj = $db->fetch_object($resql); - if ($obj) $balance=$obj->total; -} -else { - dol_print_error($db); -} -print '"; -print ''; -print "\n"; - -print "
'.$lien.'
'.$langs->trans("Month").''.$annee.'
 '.$langs->trans("Debit").''.$langs->trans("Credit").'
".dol_print_date(dol_mktime(1,1,1,$mois,1,2000),"%B")." '; - if ($decaiss[$case]>0) - { - print price($decaiss[$case]); - $totsorties[$annee]+=$decaiss[$case]; - } - print " '; - if ($encaiss[$case]>0) - { - print price($encaiss[$case]); - $totentrees[$annee]+=$encaiss[$case]; - } - print "
'.$langs->trans("Total")."'.price($totsorties[$annee]).''.price($totentrees[$annee]).'
 
'.$langs->trans("CurrentBalance")."'.price($balance).'
"; - -// BUILDING GRAPHICS - -$datetime = dol_now(); -$year = dol_print_date($datetime, "%Y"); -$month = dol_print_date($datetime, "%m"); -$day = dol_print_date($datetime, "%d"); -if (! empty($_GET["year"])) $year=sprintf("%04d",$_GET["year"]); -if (! empty($_GET["month"])) $month=sprintf("%02d",$_GET["month"]); - -$result=dol_mkdir($conf->banque->dir_temp); -if ($result < 0) -{ - $langs->load("errors"); - $error++; - $mesg='
'.$langs->trans("ErrorFailedToCreateDir").'
'; -} -else -{ - // Definition de $width et $height - $width = 550; - $height = 300; - - // Calcul de $min et $max - $sql = "SELECT MIN(b.datev) as min, MAX(b.datev) as max"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; - $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; - $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; - if ($id && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$id.")"; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $obj = $db->fetch_object($resql); - $min = $db->jdate($obj->min); - $max = $db->jdate($obj->max); - } - else - { - dol_print_error($db); - } - $log="graph.php: min=".$min." max=".$max; - dol_syslog($log); - -// CRED PART - // Chargement du tableau des années - $tblyear[0] = array(); - $tblyear[1] = array(); - $tblyear[2] = array(); - - for ($annee=0;$annee<3;$annee++) - { - $sql = "SELECT date_format(b.datev,'%m')"; - $sql.= ", SUM(b.amount)"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; - $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; - $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; - $sql.= " AND b.datev >= '".($year-$annee)."-01-01 00:00:00'"; - $sql.= " AND b.datev <= '".($year-$annee)."-12-31 23:59:59'"; - $sql.= " AND b.amount > 0"; - if ($id && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$id.")"; - $sql .= " GROUP BY date_format(b.datev,'%m');"; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $row = $db->fetch_row($resql); - $tblyear[$annee][$row[0]] = $row[1]; - $i++; - } - $db->free($resql); - - } - else - { - dol_print_error($db); - } - } - // Chargement de labels et data_xxx pour tableau 4 Mouvements - $labels = array(); - $data_year_0 = array(); - $data_year_1 = array(); - $data_year_2 = array(); - - for ($i = 0 ; $i < 12 ; $i++) - { - $data_year_0[$i] = isset($tblyear[0][substr("0".($i+1),-2)]) ? $tblyear[0][substr("0".($i+1),-2)] : 0; - $data_year_1[$i] = isset($tblyear[1][substr("0".($i+1),-2)]) ? $tblyear[1][substr("0".($i+1),-2)] : 0; - $data_year_2[$i] = isset($tblyear[2][substr("0".($i+1),-2)]) ? $tblyear[2][substr("0".($i+1),-2)] : 0; - $labels[$i] = dol_print_date(dol_mktime(12,0,0,$i+1,1,2000),"%b"); - $datamin[$i] = 0; - } - - // Fabrication tableau 4b - $file= $conf->banque->dir_temp."/credmovement".$id."-".$year.".png"; - $fileurl=DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/credmovement".$id."-".$year.".png"; - $title=$langs->transnoentities("Credit").' - '.$langs->transnoentities("Year").': '.($year-2).' - '.($year-1)." - ".$year; - $graph_datas=array(); - for($i=0;$i<12;$i++) - { - $graph_datas[$i]=array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]); - } - - $px1 = new DolGraph(); - $px1->SetData($graph_datas); - $px1->SetLegend(array(($year),($year-1),($year-2))); - $px1->SetLegendWidthMin(180); - $px1->SetMaxValue($px1->GetCeilMaxValue()<0?0:$px1->GetCeilMaxValue()); - $px1->SetMinValue($px1->GetFloorMinValue()>0?0:$px1->GetFloorMinValue()); - $px1->SetTitle($title); - $px1->SetWidth($width); - $px1->SetHeight($height); - $px1->SetType(array('line','line','line')); - $px1->SetShading(3); - $px1->setBgColor('onglet'); - $px1->setBgColorGrid(array(255,255,255)); - $px1->SetHorizTickIncrement(1); - $px1->SetPrecisionY(0); - $px1->draw($file,$fileurl); - - $show1 = $px1->show(); - - unset($graph_datas); - unset($px1); - unset($tblyear[0]); - unset($tblyear[1]); - unset($tblyear[2]); - -// DEDBT PART - // Chargement du tableau des années - $tblyear[0] = array(); - $tblyear[1] = array(); - $tblyear[2] = array(); - - for ($annee=0;$annee<3;$annee++) - { - $sql = "SELECT date_format(b.datev,'%m')"; - $sql.= ", SUM(b.amount)"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; - $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; - $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; - $sql.= " AND b.datev >= '".($year-$annee)."-01-01 00:00:00'"; - $sql.= " AND b.datev <= '".($year-$annee)."-12-31 23:59:59'"; - $sql.= " AND b.amount < 0"; - if ($id && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$id.")"; - $sql .= " GROUP BY date_format(b.datev,'%m');"; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $row = $db->fetch_row($resql); - $tblyear[$annee][$row[0]] = abs($row[1]); - $i++; - } - $db->free($resql); - } - else - { - dol_print_error($db); - } - } - // Chargement de labels et data_xxx pour tableau 4 Mouvements - $labels = array(); - $data_year_0 = array(); - $data_year_1 = array(); - $data_year_2 = array(); - - for ($i = 0 ; $i < 12 ; $i++) - { - $data_year_0[$i] = isset($tblyear[0][substr("0".($i+1),-2)]) ? $tblyear[0][substr("0".($i+1),-2)] : 0; - $data_year_1[$i] = isset($tblyear[1][substr("0".($i+1),-2)]) ? $tblyear[1][substr("0".($i+1),-2)] : 0; - $data_year_2[$i] = isset($tblyear[2][substr("0".($i+1),-2)]) ? $tblyear[2][substr("0".($i+1),-2)] : 0; - $labels[$i] = dol_print_date(dol_mktime(12,0,0,$i+1,1,2000),"%b"); - $datamin[$i] = 0; - } - - $file= $conf->banque->dir_temp."/debmovement".$id."-".$year.".png"; - $fileurl= DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/debmovement".$id."-".$year.".png"; - $title=$langs->transnoentities("Debit").' - '.$langs->transnoentities("Year").': '.($year-2).' - '.($year-1)." - ".$year; - $graph_datas=array(); - for($i=0;$i<12;$i++) - { - $graph_datas[$i]=array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]); - } - - $px2 = new DolGraph(); - $px2->SetData($graph_datas); - $px2->SetLegend(array(($year),($year-1),($year-2))); - $px2->SetLegendWidthMin(180); - $px2->SetMaxValue($px2->GetCeilMaxValue()<0?0:$px2->GetCeilMaxValue()); - $px2->SetMinValue($px2->GetFloorMinValue()>0?0:$px2->GetFloorMinValue()); - $px2->SetTitle($title); - $px2->SetWidth($width); - $px2->SetHeight($height); - $px2->SetType(array('line','line','line')); - $px2->SetShading(3); - $px2->setBgColor('onglet'); - $px2->setBgColorGrid(array(255,255,255)); - $px2->SetHorizTickIncrement(1); - $px2->SetPrecisionY(0); - $px2->draw($file,$fileurl); - - $show2 = $px2->show(); - - unset($graph_datas); - unset($px2); - unset($tblyear[0]); - unset($tblyear[1]); - unset($tblyear[2]); - - print ''; - print ''; - print '
'; - print $show1; - print ' '; - print $show2; - print '
'; -} - - -print "\n\n"; - -llxFooter(); -$db->close(); -?> + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2013 Charles-Fr BENKE + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/bank/annuel.php + * \ingroup banque + * \brief Page to report input-output of a bank account + */ + +require('../../main.inc.php'); +require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; + +$langs->load("banks"); +$langs->load("categories"); + +$id=GETPOST('account'); +$ref=GETPOST('ref'); + +// Security check +$fieldid = (! empty($ref)?$ref:$id); +$fieldname = isset($ref)?'ref':'rowid'; +if ($user->societe_id) $socid=$user->societe_id; +$result=restrictedArea($user,'banque',$fieldid,'bank_account','','',$fieldname); + +$year_start=GETPOST('year_start'); +$year_current = strftime("%Y",time()); +if (! $year_start) +{ + $year_start = $year_current - 2; + $year_end = $year_current; +} +else +{ + $year_end=$year_start+2; +} + + +llxHeader(); + +$form = new Form($db); + +// Get account informations +$acct = new Account($db); +if ($id > 0 && ! preg_match('/,/', $id)) // if for a particular account and not a list +{ + $result=$acct->fetch($id); + $id=$acct->id; +} +if (! empty($ref)) +{ + $result=$acct->fetch(0, $ref); + $id=$acct->id; +} + + +// Ce rapport de tresorerie est base sur llx_bank (car doit inclure les transactions sans facture) +// plutot que sur llx_paiement + llx_paiementfourn + +$sql = "SELECT SUM(b.amount)"; +$sql.= ", date_format(b.dateo,'%Y-%m') as dm"; +$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; +$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; +$sql.= " WHERE b.fk_account = ba.rowid"; +$sql.= " AND ba.entity = ".$conf->entity; +$sql.= " AND b.amount >= 0"; +if (! empty($id)) + $sql .= " AND b.fk_account IN (".$db->escape($id).")"; +$sql.= " GROUP BY dm"; + +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $encaiss[$row[1]] = $row[0]; + $i++; + } +} +else +{ + dol_print_error($db); +} + +$sql = "SELECT SUM(b.amount)"; +$sql.= ", date_format(b.dateo,'%Y-%m') as dm"; +$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; +$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; +$sql.= " WHERE b.fk_account = ba.rowid"; +$sql.= " AND ba.entity = ".$conf->entity; +$sql.= " AND b.amount <= 0"; +if (! empty($id)) + $sql .= " AND b.fk_account IN (".$db->escape($id).")"; +$sql.= " GROUP BY dm"; + +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $decaiss[$row[1]] = -$row[0]; + $i++; + } +} +else +{ + dol_print_error($db); +} + + +// Onglets +$head=bank_prepare_head($acct); +dol_fiche_head($head,'annual',$langs->trans("FinancialAccount"),0,'account'); + +$title=$langs->trans("FinancialAccount")." : ".$acct->label; +$lien=($year_start?"".img_previous()." ".$langs->trans("Year")." ".img_next()."":""); + +print ''; + +$linkback = ''.$langs->trans("BackToList").''; + +// Ref +print ''; +print ''; + +// Label +print ''; +print ''; + +print '
'.$langs->trans("Ref").''; +if ($_GET["account"]) +{ + if (! preg_match('/,/', $id)) + { + print $form->showrefnav($acct, 'ref', $linkback, 1, 'ref'); + } + else + { + $bankaccount=new Account($db); + $listid=explode(',', $id); + foreach($listid as $key => $aId) + { + $bankaccount->fetch($aId); + $bankaccount->label=$bankaccount->ref; + print $bankaccount->getNomUrl(1); + if ($key < (count($listid)-1)) print ', '; + } + } +} +else +{ + print $langs->trans("ALL"); +} +print '
'.$langs->trans("Label").''; +if (! empty($id)) +{ + print $acct->label; +} +else +{ + print $langs->trans("AllAccounts"); +} +print '
'; + +print '
'; + +// Affiche tableau +print ''; + +print ''; + +print ''; +for ($annee = $year_start ; $annee <= $year_end ; $annee++) +{ + print ''; +} +print ''; + +print ''; +print ''; +for ($annee = $year_start ; $annee <= $year_end ; $annee++) +{ + print ''; +} +print ''; + +$var=true; +for ($mois = 1 ; $mois < 13 ; $mois++) +{ + $var=!$var; + print ''; + print ""; + for ($annee = $year_start ; $annee <= $year_end ; $annee++) + { + $case = sprintf("%04s-%02s",$annee,$mois); + + print '"; + + print '"; + } + print ''; +} + +// Total debit-credit +print '"; +for ($annee = $year_start ; $annee <= $year_end ; $annee++) +{ + print ''; +} +print "\n"; + +// Ligne vierge +print ''; +$nbcol=0; +for ($annee = $year_start ; $annee <= $year_end ; $annee++) +{ + $nbcol+=2; +} +print "\n"; + +// Solde actuel +$balance=0; + +$sql = "SELECT SUM(b.amount) as total"; +$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; +$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; +$sql.= " WHERE b.fk_account = ba.rowid"; +$sql.= " AND ba.entity = ".$conf->entity; +if (! empty($id)) + $sql.= " AND b.fk_account IN (".$db->escape($id).")"; + +$resql=$db->query($sql); +if ($resql) +{ + $obj = $db->fetch_object($resql); + if ($obj) $balance=$obj->total; +} +else { + dol_print_error($db); +} +print '"; +print ''; +print "\n"; + +print "
'.$lien.'
'.$langs->trans("Month").''.$annee.'
 '.$langs->trans("Debit").''.$langs->trans("Credit").'
".dol_print_date(dol_mktime(1,1,1,$mois,1,2000),"%B")." '; + if ($decaiss[$case]>0) + { + print price($decaiss[$case]); + $totsorties[$annee]+=$decaiss[$case]; + } + print " '; + if ($encaiss[$case]>0) + { + print price($encaiss[$case]); + $totentrees[$annee]+=$encaiss[$case]; + } + print "
'.$langs->trans("Total")."'.price($totsorties[$annee]).''.price($totentrees[$annee]).'
 
'.$langs->trans("CurrentBalance")."'.price($balance).'
"; + +// BUILDING GRAPHICS + +$datetime = dol_now(); +$year = dol_print_date($datetime, "%Y"); +$month = dol_print_date($datetime, "%m"); +$day = dol_print_date($datetime, "%d"); +if (! empty($_GET["year"])) $year=sprintf("%04d",$_GET["year"]); +if (! empty($_GET["month"])) $month=sprintf("%02d",$_GET["month"]); + +$result=dol_mkdir($conf->banque->dir_temp); +if ($result < 0) +{ + $langs->load("errors"); + $error++; + $mesg='
'.$langs->trans("ErrorFailedToCreateDir").'
'; +} +else +{ + // Definition de $width et $height + $width = 550; + $height = 300; + + // Calcul de $min et $max + $sql = "SELECT MIN(b.datev) as min, MAX(b.datev) as max"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= " WHERE b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; + if ($id && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$id.")"; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $obj = $db->fetch_object($resql); + $min = $db->jdate($obj->min); + $max = $db->jdate($obj->max); + } + else + { + dol_print_error($db); + } + $log="graph.php: min=".$min." max=".$max; + dol_syslog($log); + +// CRED PART + // Chargement du tableau des années + $tblyear[0] = array(); + $tblyear[1] = array(); + $tblyear[2] = array(); + + for ($annee=0;$annee<3;$annee++) + { + $sql = "SELECT date_format(b.datev,'%m')"; + $sql.= ", SUM(b.amount)"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= " WHERE b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND b.datev >= '".($year-$annee)."-01-01 00:00:00'"; + $sql.= " AND b.datev <= '".($year-$annee)."-12-31 23:59:59'"; + $sql.= " AND b.amount > 0"; + if ($id && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$id.")"; + $sql .= " GROUP BY date_format(b.datev,'%m');"; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $tblyear[$annee][$row[0]] = $row[1]; + $i++; + } + $db->free($resql); + + } + else + { + dol_print_error($db); + } + } + // Chargement de labels et data_xxx pour tableau 4 Mouvements + $labels = array(); + $data_year_0 = array(); + $data_year_1 = array(); + $data_year_2 = array(); + + for ($i = 0 ; $i < 12 ; $i++) + { + $data_year_0[$i] = isset($tblyear[0][substr("0".($i+1),-2)]) ? $tblyear[0][substr("0".($i+1),-2)] : 0; + $data_year_1[$i] = isset($tblyear[1][substr("0".($i+1),-2)]) ? $tblyear[1][substr("0".($i+1),-2)] : 0; + $data_year_2[$i] = isset($tblyear[2][substr("0".($i+1),-2)]) ? $tblyear[2][substr("0".($i+1),-2)] : 0; + $labels[$i] = dol_print_date(dol_mktime(12,0,0,$i+1,1,2000),"%b"); + $datamin[$i] = 0; + } + + // Fabrication tableau 4b + $file= $conf->banque->dir_temp."/credmovement".$id."-".$year.".png"; + $fileurl=DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/credmovement".$id."-".$year.".png"; + $title=$langs->transnoentities("Credit").' - '.$langs->transnoentities("Year").': '.($year-2).' - '.($year-1)." - ".$year; + $graph_datas=array(); + for($i=0;$i<12;$i++) + { + $graph_datas[$i]=array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]); + } + + $px1 = new DolGraph(); + $px1->SetData($graph_datas); + $px1->SetLegend(array(($year),($year-1),($year-2))); + $px1->SetLegendWidthMin(180); + $px1->SetMaxValue($px1->GetCeilMaxValue()<0?0:$px1->GetCeilMaxValue()); + $px1->SetMinValue($px1->GetFloorMinValue()>0?0:$px1->GetFloorMinValue()); + $px1->SetTitle($title); + $px1->SetWidth($width); + $px1->SetHeight($height); + $px1->SetType(array('line','line','line')); + $px1->SetShading(3); + $px1->setBgColor('onglet'); + $px1->setBgColorGrid(array(255,255,255)); + $px1->SetHorizTickIncrement(1); + $px1->SetPrecisionY(0); + $px1->draw($file,$fileurl); + + $show1 = $px1->show(); + + unset($graph_datas); + unset($px1); + unset($tblyear[0]); + unset($tblyear[1]); + unset($tblyear[2]); + +// DEDBT PART + // Chargement du tableau des années + $tblyear[0] = array(); + $tblyear[1] = array(); + $tblyear[2] = array(); + + for ($annee=0;$annee<3;$annee++) + { + $sql = "SELECT date_format(b.datev,'%m')"; + $sql.= ", SUM(b.amount)"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= " WHERE b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " AND b.datev >= '".($year-$annee)."-01-01 00:00:00'"; + $sql.= " AND b.datev <= '".($year-$annee)."-12-31 23:59:59'"; + $sql.= " AND b.amount < 0"; + if ($id && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$id.")"; + $sql .= " GROUP BY date_format(b.datev,'%m');"; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $tblyear[$annee][$row[0]] = abs($row[1]); + $i++; + } + $db->free($resql); + } + else + { + dol_print_error($db); + } + } + // Chargement de labels et data_xxx pour tableau 4 Mouvements + $labels = array(); + $data_year_0 = array(); + $data_year_1 = array(); + $data_year_2 = array(); + + for ($i = 0 ; $i < 12 ; $i++) + { + $data_year_0[$i] = isset($tblyear[0][substr("0".($i+1),-2)]) ? $tblyear[0][substr("0".($i+1),-2)] : 0; + $data_year_1[$i] = isset($tblyear[1][substr("0".($i+1),-2)]) ? $tblyear[1][substr("0".($i+1),-2)] : 0; + $data_year_2[$i] = isset($tblyear[2][substr("0".($i+1),-2)]) ? $tblyear[2][substr("0".($i+1),-2)] : 0; + $labels[$i] = dol_print_date(dol_mktime(12,0,0,$i+1,1,2000),"%b"); + $datamin[$i] = 0; + } + + $file= $conf->banque->dir_temp."/debmovement".$id."-".$year.".png"; + $fileurl= DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/debmovement".$id."-".$year.".png"; + $title=$langs->transnoentities("Debit").' - '.$langs->transnoentities("Year").': '.($year-2).' - '.($year-1)." - ".$year; + $graph_datas=array(); + for($i=0;$i<12;$i++) + { + $graph_datas[$i]=array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]); + } + + $px2 = new DolGraph(); + $px2->SetData($graph_datas); + $px2->SetLegend(array(($year),($year-1),($year-2))); + $px2->SetLegendWidthMin(180); + $px2->SetMaxValue($px2->GetCeilMaxValue()<0?0:$px2->GetCeilMaxValue()); + $px2->SetMinValue($px2->GetFloorMinValue()>0?0:$px2->GetFloorMinValue()); + $px2->SetTitle($title); + $px2->SetWidth($width); + $px2->SetHeight($height); + $px2->SetType(array('line','line','line')); + $px2->SetShading(3); + $px2->setBgColor('onglet'); + $px2->setBgColorGrid(array(255,255,255)); + $px2->SetHorizTickIncrement(1); + $px2->SetPrecisionY(0); + $px2->draw($file,$fileurl); + + $show2 = $px2->show(); + + unset($graph_datas); + unset($px2); + unset($tblyear[0]); + unset($tblyear[1]); + unset($tblyear[2]); + + print ''; + print ''; + print '
'; + print $show1; + print ' '; + print $show2; + print '
'; +} + + +print "\n\n"; + +llxFooter(); +$db->close(); +?> diff --git a/htdocs/compta/bank/releve.php b/htdocs/compta/bank/releve.php index 3c02d6fd9db..2d9ac9cd86e 100644 --- a/htdocs/compta/bank/releve.php +++ b/htdocs/compta/bank/releve.php @@ -277,8 +277,8 @@ else $sql.= " AND b.fk_account = ba.rowid"; $sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day + dol_syslog("sql=".$sql); $result = $db->query($sql); - if ($result) { $var=True; diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index f62b2fcc594..4efd90c10aa 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -35,6 +35,7 @@ class ChargeSociales extends CommonObject public $table_element='chargesociales'; var $id; + var $ref; var $date_ech; var $lib; var $type; diff --git a/htdocs/compta/tva/fiche.php b/htdocs/compta/tva/fiche.php index a95f7b85963..a31b4030b65 100644 --- a/htdocs/compta/tva/fiche.php +++ b/htdocs/compta/tva/fiche.php @@ -31,7 +31,8 @@ $langs->load("compta"); $langs->load("banks"); $langs->load("bills"); -$id=$_REQUEST["id"]; +$id=GETPOST("id"); +$action=GETPOST('action'); $mesg = ''; @@ -40,17 +41,25 @@ $socid = isset($_GET["socid"])?$_GET["socid"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'tax', '', '', 'charges'); +$tva = new Tva($db); + // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('taxvatcard')); -/** - * Action ajout paiement tva - */ -if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) -{ - $tva = new Tva($db); +/** + * Actions + */ + +if ($_POST["cancel"] == $langs->trans("Cancel")) +{ + header("Location: reglement.php"); + exit; +} + +if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) +{ $db->begin(); $datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]); @@ -74,13 +83,12 @@ if ($_POST["action"] == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) { $db->rollback(); $mesg='
'.$tva->error.'
'; - $_GET["action"]="create"; + $action="create"; } } -if ($_GET["action"] == 'delete') +if ($action == 'delete') { - $tva = new Tva($db); $result=$tva->fetch($_GET['id']); if ($tva->rappro == 0) @@ -143,7 +151,7 @@ if ($id) } // Formulaire saisie tva -if ($_GET["action"] == 'create') +if ($action == 'create') { print "
\n"; print ''; @@ -223,6 +231,9 @@ if ($id) print $vatpayment->ref; print ''; + // Label + print ''.$langs->trans("Label").''.$vatpayment->label.''; + print ""; print ''.$langs->trans("DatePayment").''; print dol_print_date($vatpayment->datep,'day'); @@ -273,5 +284,4 @@ if ($id) $db->close(); llxFooter(); - -?> +?> \ No newline at end of file diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index aa7339cb7ca..de42a730b2b 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -46,7 +46,7 @@ function societe_prepare_head($object) if ($object->client==1 || $object->client==2 || $object->client==3) { $head[$h][0] = DOL_URL_ROOT.'/comm/fiche.php?socid='.$object->id; - $head[$h][1]=''; + $head[$h][1] = ''; if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && ($object->client==2 || $object->client==3)) $head[$h][1] .= $langs->trans("Prospect"); if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && $object->client==3) $head[$h][1] .= '/'; if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && ($object->client==1 || $object->client==3)) $head[$h][1] .= $langs->trans("Customer"); @@ -60,7 +60,7 @@ function societe_prepare_head($object) $head[$h][2] = 'supplier'; $h++; } - if (! empty($conf->agenda->enabled)) + if (! empty($conf->agenda->enabled) && !empty($user->right->agenda->lire)) { $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id; $head[$h][1] = $langs->trans("Agenda"); @@ -68,7 +68,7 @@ function societe_prepare_head($object) $h++; } //show categorie tab - if (! empty($conf->categorie->enabled)) + if (! empty($conf->categorie->enabled) && !empty($user->right->categorie->lire)) { $type = 2; if ($object->fournisseur) $type = 1; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c440b8d33dd..9f543529379 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3323,7 +3323,7 @@ function picto_required() * * @param string $StringHtml String to clean * @param string $removelinefeed Replace also all lines feeds by a space - * @param string $pagecodeto Encoding of input string + * @param string $pagecodeto Encoding of input/output string * @return string String cleaned */ function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8') diff --git a/htdocs/core/lib/invoice2.lib.php b/htdocs/core/lib/invoice2.lib.php index 715ff2f877a..dd9e1ba987d 100644 --- a/htdocs/core/lib/invoice2.lib.php +++ b/htdocs/core/lib/invoice2.lib.php @@ -42,9 +42,10 @@ require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'); * @param int $usestdout Add information onto standard output * @param int $regenerate ''=Use existing PDF files, 'nameofpdf'=Regenerate all PDF files using the template * @param string $option Suffix to add into file name of generated PDF + * @param string $paymentbankid Only if payment on this bank account id * @return int Error code */ -function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $option='') +function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $option='', $paymentbankid='') { $sql = "SELECT DISTINCT f.rowid, f.facnumber"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; @@ -71,17 +72,25 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte $sqlwhere.= " f.fk_statut > 0"; $sqlwhere.= " AND pf.fk_paiement IS NULL"; } - if (in_array('payments',$filter)) + if (in_array('payments',$filter) || in_array('bank',$filter)) { - $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf,"; - $sql.= " ".MAIN_DB_PREFIX."paiement as p"; + $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; + if (in_array('bank',$filter)) $sql.= ", ".MAIN_DB_PREFIX."bank as b"; if (empty($sqlwhere)) $sqlwhere=' WHERE '; else $sqlwhere.=" AND"; $sqlwhere.= " f.fk_statut > 0"; $sqlwhere.= " AND f.rowid = pf.fk_facture"; $sqlwhere.= " AND pf.fk_paiement = p.rowid"; - $sqlwhere.= " AND p.datep >= '".$db->idate($paymentdateafter)."'"; - $sqlwhere.= " AND p.datep <= '".$db->idate($paymentdatebefore)."'"; + if (in_array('payments',$filter)) + { + $sqlwhere.= " AND p.datep >= '".$db->idate($paymentdateafter)."'"; + $sqlwhere.= " AND p.datep <= '".$db->idate($paymentdatebefore)."'"; + } + if (in_array('bank',$filter)) + { + $sqlwhere.= " AND p.fk_bank = b.rowid"; + $sqlwhere.= " AND b.fk_account = ".$paymentbankid; + } $sqlorder = " ORDER BY p.datep ASC"; } if (in_array('nodeposit',$filter)) diff --git a/htdocs/core/modules/export/export_csv.modules.php b/htdocs/core/modules/export/export_csv.modules.php index 902b75584cf..53b1e557f25 100644 --- a/htdocs/core/modules/export/export_csv.modules.php +++ b/htdocs/core/modules/export/export_csv.modules.php @@ -187,9 +187,10 @@ class ExportCsv extends ModeleExports * @param array $array_export_fields_label Array with list of label of fields * @param array $array_selected_sorted Array with list of field to export * @param Translate $outputlangs Object lang to translate values + * @param array $array_types Array with types of fields * @return int <0 if KO, >0 if OK */ - function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs) + function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs,$array_types) { global $conf; @@ -204,7 +205,7 @@ class ExportCsv extends ModeleExports foreach($array_selected_sorted as $code => $value) { - $newvalue=$outputlangs->transnoentities($array_export_fields_label[$code]); + $newvalue=$outputlangs->transnoentities($array_export_fields_label[$code]); // newvalue is now $outputlangs->charset_output encoded $newvalue=$this->csv_clean($newvalue,$outputlangs->charset_output); fwrite($this->handle,$newvalue.$this->separator); @@ -242,15 +243,12 @@ class ExportCsv extends ModeleExports if (strpos($code,' as ') == 0) $alias=str_replace(array('.','-'),'_',$code); else $alias=substr($code, strpos($code, ' as ') + 4); if (empty($alias)) dol_print_error('','Bad value for field with key='.$code.'. Try to redefine export.'); - - $newvalue=$outputlangs->convToOutputCharset($objp->$alias); + + $newvalue=$outputlangs->convToOutputCharset($objp->$alias); // objp->$alias must be utf8 encoded as any var in memory // newvalue is now $outputlangs->charset_output encoded $typefield=isset($array_types[$code])?$array_types[$code]:''; - + // Translation newvalue - if (preg_match('/^\((.*)\)$/i',$newvalue,$reg)) - { - $newvalue=$outputlangs->transnoentities($reg[1]); - } + if (preg_match('/^\((.*)\)$/i',$newvalue,$reg)) $newvalue=$outputlangs->transnoentities($reg[1]); $newvalue=$this->csv_clean($newvalue,$outputlangs->charset_output); @@ -284,11 +282,12 @@ class ExportCsv extends ModeleExports return 0; } + /** * Clean a cell to respect rules of CSV file cells * * @param string $newvalue String to clean - * @param string $charset Output character set + * @param string $charset Input AND Output character set * @return string Value cleaned */ function csv_clean($newvalue, $charset) @@ -296,7 +295,9 @@ class ExportCsv extends ModeleExports $addquote=0; // Rule Dolibarr: No HTML + //print $charset.' '.$newvalue."\n"; $newvalue=dol_string_nohtmltag($newvalue,1,$charset); + //print $charset.' '.$newvalue."\n"; // Rule 1 CSV: No CR, LF in cells $newvalue=str_replace("\r",'',$newvalue); diff --git a/htdocs/core/modules/export/export_excel.modules.php b/htdocs/core/modules/export/export_excel.modules.php index 8f6801e8521..ea0110dfe9b 100644 --- a/htdocs/core/modules/export/export_excel.modules.php +++ b/htdocs/core/modules/export/export_excel.modules.php @@ -158,7 +158,7 @@ class ExportExcel extends ModeleExports $outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO } - dol_syslog("ExportExcel::open_file file=".$file); + dol_syslog(get_class($this)."::open_file file=".$file); $this->file=$file; $ret=1; @@ -187,7 +187,7 @@ class ExportExcel extends ModeleExports $this->workbook->setActiveSheetIndex(0); $this->workbook->getActiveSheet()->setTitle($outputlangs->trans("Sheet")); - $this->workbook->getActiveSheet()->getDefaultRowDimension()->setRowHeight(15); + $this->workbook->getActiveSheet()->getDefaultRowDimension()->setRowHeight(16); } return $ret; } @@ -212,9 +212,10 @@ class ExportExcel extends ModeleExports * @param array $array_export_fields_label Array with list of label of fields * @param array $array_selected_sorted Array with list of field to export * @param Translate $outputlangs Object lang to translate values + * @param array $array_types Array with types of fields * @return int <0 if KO, >0 if OK */ - function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs) + function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs,$array_types) { // Create a format for the column headings if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) @@ -231,7 +232,7 @@ class ExportExcel extends ModeleExports else { $this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true); - $this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); + $this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); } $this->col=0; @@ -247,6 +248,10 @@ class ExportExcel extends ModeleExports else { $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, $outputlangs->transnoentities($alias)); + if (! empty($array_types[$code]) && in_array($array_types[$code],array('Date','Number','TextAuto'))) // Set autowidth for some types + { + $this->workbook->getActiveSheet()->getColumnDimension($this->column2Letter($this->col + 1))->setAutoSize(true); + } } $this->col++; } @@ -341,18 +346,17 @@ class ExportExcel extends ModeleExports $this->worksheet->write($this->row, $this->col, $newvalue); } else - { - if ($typefield == 'Text') + { + if ($typefield == 'Text' || $typefield == 'TextAuto') { //$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->setValueExplicit($newvalue, PHPExcel_Cell_DataType::TYPE_STRING); $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, (string) $newvalue); $coord=$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->getCoordinate(); $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('@'); + $this->workbook->getActiveSheet()->getStyle($coord)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); } else { - //$coord=$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->getCoordinate(); - //if ($typefield == 'Text') $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('@'); $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, $newvalue); } } @@ -412,6 +416,29 @@ class ExportExcel extends ModeleExports return $newvalue; } + + + /** + * Convert a column to letter (1->A, 0->B, 27->AA, ...) + * + * @param int $c Column position + * @return string Letter + */ + function column2Letter($c) + { + + $c = intval($c); + if ($c <= 0) return ''; + + while ($c != 0) + { + $p = ($c - 1) % 26; + $c = intval(($c - $p) / 26); + $letter = chr(65 + $p) . $letter; + } + + return $letter; + } } ?> diff --git a/htdocs/core/modules/export/export_excel2007.modules.php b/htdocs/core/modules/export/export_excel2007.modules.php index 609bbc2d660..6d9a585e6be 100755 --- a/htdocs/core/modules/export/export_excel2007.modules.php +++ b/htdocs/core/modules/export/export_excel2007.modules.php @@ -72,310 +72,6 @@ class ExportExcel2007 extends ExportExcel $this->row=0; } - /** - * getDriverLabel - * - * @return int - */ - function getDriverId() - { - return $this->id; - } - - /** - * getDriverLabel - * - * @return string Return driver label - */ - function getDriverLabel() - { - return $this->label; - } - - /** - * getDriverDesc - * - * @return string - */ - function getDriverDesc() - { - return $this->desc; - } - - /** - * getDriverExtension - * - * @return string - */ - function getDriverExtension() - { - return $this->extension; - } - - /** - * getDriverVersion - * - * @return string - */ - function getDriverVersion() - { - return $this->version; - } - - /** - * getLibLabel - * - * @return string - */ - function getLibLabel() - { - return $this->label_lib; - } - - /** - * getLibVersion - * - * @return string - */ - function getLibVersion() - { - return $this->version_lib; - } - - - /** - * Open output file - * - * @param string $file File name to generate - * @param Translate $outputlangs Output language object - * @return int <0 if KO, >=0 if OK - */ - function open_file($file,$outputlangs) - { - global $user,$conf,$langs; - - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) - { - $outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO - } - - dol_syslog("ExportExcel::open_file file=".$file); - $this->file=$file; - - $ret=1; - - $outputlangs->load("exports"); - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) - { - require_once PHP_WRITEEXCEL_PATH.'class.writeexcel_workbookbig.inc.php'; - require_once PHP_WRITEEXCEL_PATH.'class.writeexcel_worksheet.inc.php'; - require_once PHP_WRITEEXCEL_PATH.'functions.writeexcel_utility.inc.php'; - $this->workbook = new writeexcel_workbookbig($file); - $this->workbook->set_tempdir($conf->export->dir_temp); // Set temporary directory - $this->workbook->set_sheetname($outputlangs->trans("Sheet")); - $this->worksheet = &$this->workbook->addworksheet(); - } - else - { - require_once PHPEXCEL_PATH.'PHPExcel.php'; - require_once PHPEXCEL_PATH.'PHPExcel/Style/Alignment.php'; - $this->workbook = new PHPExcel(); - $this->workbook->getProperties()->setCreator($user->getFullName($outputlangs).' - Dolibarr '.DOL_VERSION); - //$this->workbook->getProperties()->setLastModifiedBy('Dolibarr '.DOL_VERSION); - $this->workbook->getProperties()->setTitle($outputlangs->trans("Export").' - '.$file); - $this->workbook->getProperties()->setSubject($outputlangs->trans("Export").' - '.$file); - $this->workbook->getProperties()->setDescription($outputlangs->trans("Export").' - '.$file); - - $this->workbook->setActiveSheetIndex(0); - $this->workbook->getActiveSheet()->setTitle($outputlangs->trans("Sheet")); - $this->workbook->getActiveSheet()->getDefaultRowDimension()->setRowHeight(16); - } - return $ret; - } - - /** - * Write header - * - * @param Translate $outputlangs Object lang to translate values - * @return int <0 if KO, >0 if OK - */ - function write_header($outputlangs) - { - //$outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO - - return 0; - } - - - /** - * Output title line into file - * - * @param array $array_export_fields_label Array with list of label of fields - * @param array $array_selected_sorted Array with list of field to export - * @param Translate $outputlangs Object lang to translate values - * @return int <0 if KO, >0 if OK - */ - function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs) - { - // Create a format for the column headings - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) - { - $outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO - - $formatheader =$this->workbook->addformat(); - $formatheader->set_bold(); - $formatheader->set_color('blue'); - //$formatheader->set_size(12); - //$formatheader->set_font("Courier New"); - //$formatheader->set_align('center'); - } - else - { - $this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true); - $this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); - } - - $this->col=0; - foreach($array_selected_sorted as $code => $value) - { - $alias=$array_export_fields_label[$code]; - //print "dd".$alias; - if (empty($alias)) dol_print_error('','Bad value for field with code='.$code.'. Try to redefine export.'); - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) - { - $this->worksheet->write($this->row, $this->col, $outputlangs->transnoentities($alias), $formatheader); - } - else - { - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, $outputlangs->transnoentities($alias)); - } - $this->col++; - } - $this->row++; - return 0; - } - - /** - * Output record line into file - * - * @param array $array_selected_sorted Array with list of field to export - * @param resource $objp A record from a fetch with all fields from select - * @param Translate $outputlangs Object lang to translate values - * @param array $array_types Array with types of fields - * @return int <0 if KO, >0 if OK - */ - function write_record($array_selected_sorted,$objp,$outputlangs,$array_types) - { - // Create a format for the column headings - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) - { - $outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO - } - - // Define first row - $this->col=0; - - foreach($array_selected_sorted as $code => $value) - { - if (strpos($code,' as ') == 0) $alias=str_replace(array('.','-'),'_',$code); - else $alias=substr($code, strpos($code, ' as ') + 4); - if (empty($alias)) dol_print_error('','Bad value for field with code='.$code.'. Try to redefine export.'); - $newvalue=$objp->$alias; - - $newvalue=$this->excel_clean($newvalue); - $typefield=isset($array_types[$code])?$array_types[$code]:''; - - // Traduction newvalue - if (preg_match('/^\((.*)\)$/i',$newvalue,$reg)) - { - $newvalue=$outputlangs->transnoentities($reg[1]); - } - else - { - $newvalue=$outputlangs->convToOutputCharset($newvalue); - } - - //var_dump($code.' '.$alias.' '.$newvalue.' '.$typefield); - - if (preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/i',$newvalue)) - { - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) - { - $formatdate=$this->workbook->addformat(); - $formatdate->set_num_format('yyyy-mm-dd'); - //$formatdate->set_num_format(0x0f); - $arrayvalue=preg_split('/[.,]/',xl_parse_date($newvalue)); - //print "x".$arrayvalue[0].'.'.strval($arrayvalue[1]).'
'; - $newvalue=strval($arrayvalue[0]).'.'.strval($arrayvalue[1]); // $newvalue=strval(36892.521); directly does not work because . will be convert into , later - $this->worksheet->write($this->row, $this->col, $newvalue, PHPExcel_Shared_Date::PHPToExcel($formatdate)); - } - else - { - $newvalue=dol_stringtotime($newvalue); - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, PHPExcel_Shared_Date::PHPToExcel($newvalue)); - $coord=$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->getCoordinate(); - $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('yyyy-mm-dd'); - } - } - elseif (preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]$/i',$newvalue)) - { - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) - { - $formatdatehour=$this->workbook->addformat(); - $formatdatehour->set_num_format('yyyy-mm-dd hh:mm:ss'); - //$formatdatehour->set_num_format(0x0f); - $arrayvalue=preg_split('/[.,]/',xl_parse_date($newvalue)); - //print "x".$arrayvalue[0].'.'.strval($arrayvalue[1]).'
'; - $newvalue=strval($arrayvalue[0]).'.'.strval($arrayvalue[1]); // $newvalue=strval(36892.521); directly does not work because . will be convert into , later - $this->worksheet->write($this->row, $this->col, $newvalue, $formatdatehour); - } - else - { - $newvalue=dol_stringtotime($newvalue); - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, PHPExcel_Shared_Date::PHPToExcel($newvalue)); - $coord=$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->getCoordinate(); - $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('yyyy-mm-dd h:mm:ss'); - } - } - else - { - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) - { - $this->worksheet->write($this->row, $this->col, $newvalue); - } - else - { - if ($typefield == 'Text') - { - //$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->setValueExplicit($newvalue, PHPExcel_Cell_DataType::TYPE_STRING); - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, (string) $newvalue); - $coord=$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->getCoordinate(); - $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('@'); - } - else - { - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, $newvalue); - } - } - } - $this->col++; - } - $this->row++; - return 0; - } - - - /** - * Write footer - * - * @param Translate $outputlangs Output language object - * @return int <0 if KO, >0 if OK - */ - function write_footer($outputlangs) - { - return 0; - } - /** * Close Excel file @@ -399,20 +95,6 @@ class ExportExcel2007 extends ExportExcel return 0; } - - /** - * Clean a cell to respect rules of Excel file cells - * - * @param string $newvalue String to clean - * @return string Value cleaned - */ - function excel_clean($newvalue) - { - // Rule Dolibarr: No HTML - $newvalue=dol_string_nohtmltag($newvalue); - - return $newvalue; - } } ?> diff --git a/htdocs/core/modules/export/export_tsv.modules.php b/htdocs/core/modules/export/export_tsv.modules.php index edc08dc6840..12062b94804 100644 --- a/htdocs/core/modules/export/export_tsv.modules.php +++ b/htdocs/core/modules/export/export_tsv.modules.php @@ -182,13 +182,14 @@ class ExportTsv extends ModeleExports * @param array $array_export_fields_label Array with list of label of fields * @param array $array_selected_sorted Array with list of field to export * @param Translate $outputlangs Object lang to translate values + * @param array $array_types Array with types of fields * @return int <0 if KO, >0 if OK */ - function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs) + function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs,$array_types) { foreach($array_selected_sorted as $code => $value) { - $newvalue=$outputlangs->transnoentities($array_export_fields_label[$code]); + $newvalue=$outputlangs->transnoentities($array_export_fields_label[$code]); // newvalue is now $outputlangs->charset_output encoded $newvalue=$this->tsv_clean($newvalue,$outputlangs->charset_output); fwrite($this->handle,$newvalue.$this->separator); @@ -218,14 +219,11 @@ class ExportTsv extends ModeleExports else $alias=substr($code, strpos($code, ' as ') + 4); if (empty($alias)) dol_print_error('','Bad value for field with code='.$code.'. Try to redefine export.'); - $newvalue=$outputlangs->convToOutputCharset($objp->$alias); + $newvalue=$outputlangs->convToOutputCharset($objp->$alias); // objp->$alias must be utf8 encoded as any var in memory // newvalue is now $outputlangs->charset_output encoded $typefield=isset($array_types[$code])?$array_types[$code]:''; // Translation newvalue - if (preg_match('/^\((.*)\)$/i',$newvalue,$reg)) - { - $newvalue=$outputlangs->transnoentities($reg[1]); - } + if (preg_match('/^\((.*)\)$/i',$newvalue,$reg)) $newvalue=$outputlangs->transnoentities($reg[1]); $newvalue=$this->tsv_clean($newvalue,$outputlangs->charset_output); @@ -262,7 +260,7 @@ class ExportTsv extends ModeleExports * Clean a cell to respect rules of TSV file cells * * @param string $newvalue String to clean - * @param string $charset Output character set + * @param string $charset Input AND Output character set * @return string Value cleaned */ function tsv_clean($newvalue, $charset) diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index 2311c6fe66e..b90922b3206 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -520,7 +520,7 @@ class Export $objmodel->write_header($outputlangs); // Genere ligne de titre - $objmodel->write_title($this->array_export_fields[$indice],$array_selected,$outputlangs); + $objmodel->write_title($this->array_export_fields[$indice],$array_selected,$outputlangs,$this->array_export_TypeFields[$indice]); $var=true; diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index a1324f774ae..03dbc54f697 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -380,6 +380,8 @@ class PaiementFourn extends Paiement $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f'; $sql.= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.$this->id; if ($filter) $sql.= ' AND '.$filter; + + dol_syslog(get_class($this).'::getBillsArray sql='.$sql); $resql = $this->db->query($sql); if ($resql) { @@ -399,7 +401,7 @@ class PaiementFourn extends Paiement else { $this->error=$this->db->error(); - dol_syslog('PaiementFourn::getBillsArray Error '.$this->error.' - sql='.$sql); + dol_syslog(get_class($this).'::getBillsArray Error '.$this->error); return -1; } } diff --git a/htdocs/langs/en_US/banks.lang b/htdocs/langs/en_US/banks.lang index de84677fc23..7a9b5644255 100644 --- a/htdocs/langs/en_US/banks.lang +++ b/htdocs/langs/en_US/banks.lang @@ -20,6 +20,8 @@ SavingAccount=Savings account SavingAccounts=Savings accounts ErrorBankLabelAlreadyExists=Financial account label already exists BankBalance=Balance +BankBalanceBefore=Balance before +BankBalanceAfter=Balance after BalanceMinimalAllowed=Minimum allowed balance BalanceMinimalDesired=Minimum desired balance InitialBankBalance=Initial balance diff --git a/htdocs/langs/fr_FR/banks.lang b/htdocs/langs/fr_FR/banks.lang index c51d915602f..bcc281626e1 100644 --- a/htdocs/langs/fr_FR/banks.lang +++ b/htdocs/langs/fr_FR/banks.lang @@ -20,6 +20,8 @@ SavingAccount=Compte épargne SavingAccounts=Comptes épargne/placements ErrorBankLabelAlreadyExists=Libellé de compte financier déjà existant BankBalance=Solde +BankBalanceBefore=Solde avant +BankBalanceAfter=Solde après BalanceMinimalAllowed=Solde minimum autorisé BalanceMinimalDesired=Solde minimum désiré InitialBankBalance=Solde initial diff --git a/htdocs/langs/fr_FR/compta.lang b/htdocs/langs/fr_FR/compta.lang index 227b6b734ad..a86676b36b9 100644 --- a/htdocs/langs/fr_FR/compta.lang +++ b/htdocs/langs/fr_FR/compta.lang @@ -140,7 +140,7 @@ SellsJournal=Journal des ventes PurchasesJournal=Journal des achats Journaux=Journaux InvoiceRef=Réf facture -Piece=Piece compta +Piece=Pièce compta DescSellsJournal=Journal des ventes DescPurchasesJournal=Journal des achats JournalNum=Journal diff --git a/scripts/bank/export-bank-receipts.php b/scripts/bank/export-bank-receipts.php index 7c4b0baec74..1d71c4edfe4 100755 --- a/scripts/bank/export-bank-receipts.php +++ b/scripts/bank/export-bank-receipts.php @@ -43,6 +43,10 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.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/tva/class/tva.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php'; // Global variables $version=DOL_VERSION; @@ -50,7 +54,10 @@ $error=0; -// -------------------- START OF YOUR CODE HERE -------------------- +/* + * Main + */ + @set_time_limit(0); print "***** ".$script_file." (".$version.") *****\n"; @@ -64,12 +71,15 @@ $model=$argv[3]; $newlangid='en_EN'; // To force a new lang id +$invoicestatic=new Facture($db); +$invoicesupplierstatic=new FactureFournisseur($db); $societestatic=new Societe($db); -$chargestatic=new ChargeSociales($db); +$chargestatic=new ChargeSociales($db); $memberstatic=new Adherent($db); $paymentstatic=new Paiement($db); -$paymentsupplierstatic=new PaiementFourn($db); -$paymentvatstatic=new TVA($db); +$paymentsupplierstatic=new PaiementFourn($db); +$paymentsocialcontributionstatic=new PaymentSocialContribution($db); +$paymentvatstatic=new Tva($db); $bankstatic=new Account($db); $banklinestatic=new AccountLine($db); @@ -100,16 +110,23 @@ if (! empty($newlangid)) $outputlangs->load("main"); $outputlangs->load("bills"); $outputlangs->load("companies"); -$outputlangs->load("banks"); +$outputlangs->load("banks"); +$outputlangs->load("members"); +$outputlangs->load("compta"); $acct=new Account($db); $result=$acct->fetch('',$bankref); if ($result <= 0) { - print "Failed to find bank account with ref ".$bankref."\n"; + print "Failed to find bank account with ref ".$bankref.".\n"; exit; } +else +{ + print "Export for bank account ".$acct->ref." (".$acct->label.").\n"; +} + // Creation de la classe d'export du model ExportXXX $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; @@ -129,220 +146,297 @@ $dirname = $conf->banque->dir_temp; $filename = 'export-bank-receipts-'.$bankref.'-'.$num.'.'.$objmodel->extension; -// Open file -print 'Create file '.$filename.' into directory '.$dirname."\n"; -dol_mkdir($dirname); -$result=$objmodel->open_file($dirname."/".$filename, $outputlangs); - -if ($result >= 0) +$array_fields=array( +'bankreceipt'=>$outputlangs->transnoentitiesnoconv("AccountStatementShort"), 'bankaccount'=>$outputlangs->transnoentitiesnoconv("BankAccount"), +'dateop'=>$outputlangs->transnoentitiesnoconv("DateOperationShort"),'dateval'=>$outputlangs->transnoentitiesnoconv("DateValueShort"),'type'=>$outputlangs->transnoentitiesnoconv("Type"), +'description'=>$outputlangs->transnoentitiesnoconv("Description"), 'thirdparty'=>$outputlangs->transnoentitiesnoconv("Tiers"), 'accountelem'=>$outputlangs->transnoentitiesnoconv("Piece"), +'debit'=>$outputlangs->transnoentitiesnoconv("Debit"), 'credit'=>$outputlangs->transnoentitiesnoconv("Credit"), +'soldbefore'=>$outputlangs->transnoentitiesnoconv("BankBalanceBefore"), 'soldafter'=>$outputlangs->transnoentitiesnoconv("BankBalanceAfter"), +'comment'=>$outputlangs->transnoentitiesnoconv("Comment") +); +$array_selected=array( +'bankreceipt'=>'bankreceipt', 'bankaccount'=>'bankaccount', +'dateop'=>'dateop','dateval'=>'dateval','type'=>'type', +'description'=>'description', 'thirdparty'=>'thirdparty', 'accountelem'=>'accountelem', +'debit'=>'debit', 'credit'=>'credit', +'soldbefore'=>'soldbefore','soldafter'=>'soldafter', +'comment'=>'comment' +); +$array_export_TypeFields=array( +'bankreceipt'=>'Text', 'bankaccount'=>'Text', +'dateop'=>'Date','dateval'=>'Date','type'=>'Text', +'description'=>'Text', 'thirdparty'=>'Text', 'accountelem'=>'Text', +'debit'=>'Number', 'credit'=>'Number', +'soldbefore'=>'Number','soldafter'=>'Number', +'comment'=>'Text' +); + + +// Recherche les ecritures pour le releve +$listofnum="'"; +$arraynum=explode(',',$num); +foreach($arraynum as $val) { - $numrows=0; + if ($listofnum != "'") $listofnum.="','"; + $listofnum.=$val; +} +$listofnum.="'"; +$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,"; +$sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,"; +$sql.= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel"; +$sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; +$sql.= ", ".MAIN_DB_PREFIX."bank as b"; +$sql.= " WHERE b.num_releve IN (".$listofnum.")"; +if (!isset($num)) $sql.= " OR b.num_releve is null"; +$sql.= " AND b.fk_account = ".$acct->id; +$sql.= " AND b.fk_account = ba.rowid"; +$sql.= $db->order("b.num_releve, b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day +//print $sql; +$resql=$db->query($sql); +if ($resql) +{ + $balancebefore=array(); - $array_fields=array( - 'bankreceipt'=>$outputlangs->transnoentitiesnoconv("AccountStatementShort"), 'bankaccount'=>$outputlangs->transnoentitiesnoconv("BankAccount"), - 'dateop'=>$outputlangs->transnoentitiesnoconv("DateOperationShort"),'dateval'=>$outputlangs->transnoentitiesnoconv("DateValueShort"),'type'=>$outputlangs->transnoentitiesnoconv("Type"), - 'description'=>$outputlangs->transnoentitiesnoconv("Description"), 'thirdparty'=>$outputlangs->transnoentitiesnoconv("Tiers"), 'invoices'=>$outputlangs->transnoentitiesnoconv("Invoices"), - 'debit'=>$outputlangs->transnoentitiesnoconv("Debit"), 'credit'=>$outputlangs->transnoentitiesnoconv("Credit"), 'sold'=>$outputlangs->transnoentitiesnoconv("Solde"), 'comment'=>$outputlangs->transnoentitiesnoconv("Comment") - ); - $array_selected=array( - 'bankreceipt'=>'bankreceipt', 'bankaccount'=>'bankaccount', - 'dateop'=>'dateop','dateval'=>'dateval','type'=>'type', - 'description'=>'description', 'thirdparty'=>'thirdparty', 'invoices'=>'invoices', - 'debit'=>'debit', 'credit'=>'credit', 'sold'=>'sold', 'comment'=>'comment' - ); - $array_export_TypeFields=array( - 'bankreceipt'=>'Text', 'bankaccount'=>'Text', - 'dateop'=>'Date','dateval'=>'Date','type'=>'Text', - 'description'=>'Text', 'thirdparty'=>'Text', 'invoices'=>'Text', - 'debit'=>'Number', 'credit'=>'Number', 'sold'=>'Number', 'comment'=>'Text' - ); + $numrows = $db->num_rows($resql); - // Genere en-tete - $objmodel->write_header($outputlangs); - - // Genere ligne de titre - $objmodel->write_title($array_fields,$array_selected,$outputlangs); - - - // Recherche les ecritures pour le releve - $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,"; - $sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,"; - $sql.= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; - $sql.= ", ".MAIN_DB_PREFIX."bank as b"; - $sql.= " WHERE b.num_releve='".$db->escape($num)."'"; - if (!isset($num)) $sql.= " OR b.num_releve is null"; - //$sql.= " AND b.fk_account = ".$acct->id; - $sql.= " AND b.fk_account = ba.rowid"; - $sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day - - $resql=$db->query($sql); - if ($resql) + if ($numrows > 0) { - $numrows = $db->num_rows($resql); + // Open file + print 'Open file '.$filename.' into directory '.$dirname."\n"; + dol_mkdir($dirname); + $result=$objmodel->open_file($dirname."/".$filename, $outputlangs); + + if ($result < 0) + { + print 'Failed to create file '.$filename.' into dir '.$dirname.'.'."\n"; + return -1; + } + + // Genere en-tete + $objmodel->write_header($outputlangs); + + // Genere ligne de titre + $objmodel->write_title($array_fields,$array_selected,$outputlangs,$array_export_TypeFields); + } - $i=0; - while ($i < $numrows) + $i=0; + while ($i < $numrows) + { + $thirdparty=''; + $accountelem=''; + $comment=''; + + $objp = $db->fetch_object($resql); + + // Calculate start balance + if (! isset($balancebefore[$objp->num_releve])) { - print "Lines ".$i."\n"; + print 'Calculate start balance for receipt '.$objp->num_releve."\n"; - $objp = $db->fetch_object($result); - $total = $total + $objp->amount; - - $var=!$var; - - // Date operation - $dateop=$db->jdate($objp->do); - - // Date de valeur - $datevalue=$db->jdate($objp->dv); - - // Num cheque - $numchq=($objp->num_chq?$objp->num_chq:''); - - // Libelle - $reg=array(); - preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parenthese on tente recherche de traduction - if ($reg[1] && $langs->trans($reg[1])!=$reg[1]) $desc=$langs->trans($reg[1]); - else $desc=$objp->label; - - /* - * Ajout les liens (societe, company...) - */ - $newline=1; - $links = $acct->get_url($objp->rowid); - foreach($links as $key=>$val) + $sql2 = "SELECT sum(b.amount) as amount"; + $sql2.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql2.= " WHERE b.num_releve < '".$db->escape($objp->num_releve)."'"; + $sql2.= " AND b.fk_account = ".$objp->bankid; + $resql2=$db->query($sql2); + if ($resql2) { - if (! $newline) print ' - '; - else print '
'; - if ($links[$key]['type']=='payment') - { - $paymentstatic->id=$links[$key]['url_id']; - $paymentstatic->ref=$langs->trans("Payment"); - print ' '.$paymentstatic->getNomUrl(1); - $newline=0; - } - elseif ($links[$key]['type']=='payment_supplier') - { - $paymentsupplierstatic->id=$links[$key]['url_id']; - $paymentsupplierstatic->ref=$langs->trans("Payment");; - print ' '.$paymentsupplierstatic->getNomUrl(1); - $newline=0; - } - elseif ($links[$key]['type']=='payment_sc') - { - print ''; - print ' '.img_object($langs->trans('ShowPayment'),'payment').' '; - print $langs->trans("SocialContributionPayment"); - print ''; - $newline=0; - } - elseif ($links[$key]['type']=='payment_vat') - { - $paymentvatstatic->id=$links[$key]['url_id']; - $paymentvatstatic->ref=$langs->trans("Payment"); - print ' '.$paymentvatstatic->getNomUrl(2); - } - elseif ($links[$key]['type']=='banktransfert') { - // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail. - if ($objp->amount > 0) - { - $banklinestatic->fetch($links[$key]['url_id']); - $bankstatic->id=$banklinestatic->fk_account; - $bankstatic->label=$banklinestatic->bank_account_label; - print ' ('.$langs->trans("from").' '; - print $bankstatic->getNomUrl(1,'transactions'); - print ' '.$langs->trans("toward").' '; - $bankstatic->id=$objp->bankid; - $bankstatic->label=$objp->bankref; - print $bankstatic->getNomUrl(1,''); - print ')'; - } - else - { - $bankstatic->id=$objp->bankid; - $bankstatic->label=$objp->bankref; - print ' ('.$langs->trans("from").' '; - print $bankstatic->getNomUrl(1,''); - print ' '.$langs->trans("toward").' '; - $banklinestatic->fetch($links[$key]['url_id']); - $bankstatic->id=$banklinestatic->fk_account; - $bankstatic->label=$banklinestatic->bank_account_label; - print $bankstatic->getNomUrl(1,'transactions'); - print ')'; - } - } - elseif ($links[$key]['type']=='company') { - print ''; - print img_object($langs->trans('ShowCustomer'),'company').' '; - print dol_trunc($links[$key]['label'],24); - print ''; - $newline=0; - } - elseif ($links[$key]['type']=='member') { - print ''; - print img_object($langs->trans('ShowMember'),'user').' '; - print $links[$key]['label']; - print ''; - $newline=0; - } - elseif ($links[$key]['type']=='sc') { - print ''; - print img_object($langs->trans('ShowBill'),'bill').' '; - print $langs->trans("SocialContribution"); - print ''; - $newline=0; - } - else { - print ''; - print $links[$key]['label']; - print ''; - $newline=0; - } + $obj2=$db->fetch_object($resql2); + $balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0); + $db->free($resql2); + } + else + { + dol_print_error($db); + exit; } - - if ($objp->amount < 0) - { - $totald = $totald + abs($objp->amount); - $debit=price($objp->amount * -1); - } - else - { - $totalc = $totalc + abs($objp->amount); - $credit=price($objp->amount); - } - - $i++; - - // end of special operation processing - $objmodel->write_record($array_selected,$objp,$outputlangs,$array_export_TypeFields); + $total = $balancebefore[$objp->num_releve]; } + $totalbefore = $total; + $total = $total + $objp->amount; + + $var=!$var; + + // Date operation + $dateop=$db->jdate($objp->do); + + // Date de valeur + $datevalue=$db->jdate($objp->dv); + + // Num cheque + $numchq=($objp->num_chq?$objp->num_chq:''); + + // Libelle + $reg=array(); + preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parenthese on tente recherche de traduction + if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) $description=$langs->transnoentitiesnoconv($reg[1]); + else $description=$objp->label; + + /* + * Ajout les liens (societe, company...) + */ + $links = $acct->get_url($objp->rowid); + foreach($links as $key=>$val) + { + if ($links[$key]['type']=='payment') + { + $paymentstatic->fetch($links[$key]['url_id']); + $tmparray=$paymentstatic->getBillsArray(''); + foreach($tmparray as $key => $val) + { + $invoicestatic->fetch($val); + if ($accountelem) $accountelem.= ', '; + $accountelem.=$invoicestatic->ref; + } + } + elseif ($links[$key]['type']=='payment_supplier') + { + $paymentsupplierstatic->fetch($links[$key]['url_id']); + $tmparray=$paymentsupplierstatic->getBillsArray(''); + foreach($tmparray as $key => $val) + { + $invoicesupplierstatic->fetch($val); + if ($accountelem) $accountelem.= ', '; + $accountelem.=$invoicesupplierstatic->ref; + } + } + elseif ($links[$key]['type']=='payment_sc') + { + $paymentsocialcontributionstatic->fetch($links[$key]['url_id']); + if ($accountelem) $accountelem.= ', '; + $accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref; + } + elseif ($links[$key]['type']=='payment_vat') + { + $paymentvatstatic->fetch($links[$key]['url_id']); + if ($accountelem) $accountelem.= ', '; + $accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref; + } + elseif ($links[$key]['type']=='banktransfert') + { + $comment=$outputlangs->transnoentitiesnoconv("Transfer"); + if ($objp->amount > 0) + { + if ($comment) $comment.= ' '; + $banklinestatic->fetch($links[$key]['url_id']); + $bankstatic->id=$banklinestatic->fk_account; + $bankstatic->label=$banklinestatic->bank_account_label; + $comment.= ' ('.$langs->transnoentitiesnoconv("from").' '; + $comment.= $bankstatic->getNomUrl(1,'transactions'); + $comment.= ' '.$langs->transnoentitiesnoconv("toward").' '; + $bankstatic->id=$objp->bankid; + $bankstatic->label=$objp->bankref; + $comment.= $bankstatic->getNomUrl(1,''); + $comment.= ')'; + } + else + { + if ($comment) $comment.= ' '; + $bankstatic->id=$objp->bankid; + $bankstatic->label=$objp->bankref; + $comment.= ' ('.$langs->transnoentitiesnoconv("from").' '; + $comment.= $bankstatic->getNomUrl(1,''); + $comment.= ' '.$langs->transnoentitiesnoconv("toward").' '; + $banklinestatic->fetch($links[$key]['url_id']); + $bankstatic->id=$banklinestatic->fk_account; + $bankstatic->label=$banklinestatic->bank_account_label; + $comment.= $bankstatic->getNomUrl(1,'transactions'); + $comment.= ')'; + } + } + elseif ($links[$key]['type']=='company') + { + if ($thirdparty) $thirdparty.= ', '; + $thirdparty.= dol_trunc($links[$key]['label'],24); + $newline=0; + } + elseif ($links[$key]['type']=='member') + { + if ($thirdparty) $accountelem.= ', '; + $thirdparty.= $links[$key]['label']; + $newline=0; + } + /*elseif ($links[$key]['type']=='sc') + { + if ($accountelem) $accountelem.= ', '; + //$accountelem.= ''; + //$accountelem.= img_object($langs->transnoentitiesnoconv('ShowBill'),'bill').' '; + $accountelem.= $langs->transnoentitiesnoconv("SocialContribution"); + //$accountelem.= ''; + $newline=0; + } + else + { + if ($accountelem) $accountelem.= ', '; + //$accountelem.= ''; + $accountelem.= $links[$key]['label']; + //$accountelem.= ''; + $newline=0; + }*/ + } + + $debit=$credit=''; + if ($objp->amount < 0) + { + $totald = $totald + abs($objp->amount); + $debit=price2num($objp->amount * -1); + } + else + { + $totalc = $totalc + abs($objp->amount); + $credit=price2num($objp->amount); + } + + $i++; + + $rec=new stdClass(); + $rec->bankreceipt=$objp->num_releve; + $rec->bankaccount=$objp->banklabel; + $rec->dateop=dol_print_date($dateop,'dayrfc'); + $rec->dateval=dol_print_date($datevalue,'dayrfc'); + $rec->type=$objp->fk_type.' '.($objp->num_chq?$objp->num_chq:''); + $rec->description=$description; + $rec->thirdparty=$thirdparty; + $rec->accountelem=$accountelem; + $rec->debit=$debit; + $rec->credit=$credit; + $rec->sold=$sold; + $rec->comment=$comment; + $rec->soldbefore=price2num($totalbefore); + $rec->soldafter=price2num($total); + + // end of special operation processing + $objmodel->write_record($array_selected,$rec,$outputlangs,$array_export_TypeFields); } - else dol_print_error($db); - print "Found ".$numrows." records\n"; + if ($numrows > 0) + { + print "Found ".$numrows." records for receipt ".$num."\n"; - // Genere en-tete - $objmodel->write_footer($outputlangs); + // Genere en-tete + $objmodel->write_footer($outputlangs); - // Close file - $objmodel->close_file(); + // Close file + $objmodel->close_file(); - print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n"; + print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n"; - $ret=0; + $ret=0; + } + else + { + print "No records found for receipt ".$num."\n"; + + $ret=0; + } } else { - print 'Failed to create file '.$filename.' into dir '.$dirname.'.'."\n"; - + dol_print_error($db); $ret=-1; } - - $db->close(); return $ret; diff --git a/scripts/company/export-contacts-xls-example.php b/scripts/company/export-contacts-xls-example.php index a07813b3606..760b351df7d 100644 --- a/scripts/company/export-contacts-xls-example.php +++ b/scripts/company/export-contacts-xls-example.php @@ -40,8 +40,6 @@ if (! isset($argv[1]) || ! $argv[1]) { } $now=$argv[1]; -// Recupere env dolibarr -$version='1.10'; require_once($path."../../htdocs/master.inc.php"); //require_once(PHP_WRITEEXCEL_PATH."/class.writeexcel_workbook.inc.php"); @@ -51,8 +49,18 @@ require_once(PHPEXCEL_PATH."/PHPExcel.php"); //require_once(PHPEXCEL_PATH."/PHPExcel/Writer/Excel2007.php"); require_once(PHPEXCEL_PATH."/PHPExcel/Writer/Excel5.php"); +// Global variables +$version=DOL_VERSION; +$error=0; +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; + $fname = DOL_DATA_ROOT.'/export-contacts.xls'; //$objPHPExcel = new writeexcel_workbook($fname); diff --git a/scripts/company/sync_contacts_dolibarr2ldap.php b/scripts/company/sync_contacts_dolibarr2ldap.php index 5cdc38537d5..a9916100218 100644 --- a/scripts/company/sync_contacts_dolibarr2ldap.php +++ b/scripts/company/sync_contacts_dolibarr2ldap.php @@ -40,18 +40,23 @@ if (! isset($argv[1]) || ! $argv[1]) { } $now=$argv[1]; -// Recupere env dolibarr -$version='1.25'; require_once($path."../../htdocs/master.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); +// Global variables +$version=DOL_VERSION; $error=0; -print "***** $script_file ($version) *****\n"; +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; print "Mails sending disabled (useless in batch mode)\n"; $conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails diff --git a/scripts/contracts/email_expire_services_to_customers.php b/scripts/contracts/email_expire_services_to_customers.php index 4a74218b843..4370314bb9d 100755 --- a/scripts/contracts/email_expire_services_to_customers.php +++ b/scripts/contracts/email_expire_services_to_customers.php @@ -55,20 +55,27 @@ $langs->load('main'); $langs->load('contracts'); +// Global variables +$version=DOL_VERSION; +$error=0; + + /* * Main */ +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; + $now=dol_now('tzserver'); $duration_value=$argv[2]; -$error = 0; print $script_file." launched with mode ".$mode.($duration_value?" delay=".$duration_value:"")."\n"; $sql = "SELECT DISTINCT s.nom as name, c.ref, cd.date_fin_validite, cd.total_ttc, p.label label, s.email, s.default_lang"; $sql .= " FROM ".MAIN_DB_PREFIX."societe AS s"; -$sql .= ", ".MAIN_DB_PREFIX."contrat AS c"; -$sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd"; +$sql .= ", ".MAIN_DB_PREFIX."contrat AS c"; +$sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product"; $sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut<5"; @@ -173,10 +180,10 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura global $conf,$langs; $newlangs=new Translate('',$conf); - $newlangs->setDefaultLang($userlang); + $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang); $newlangs->load("main"); $newlangs->load("contracts"); - + if ($duration_value) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value); else diff --git a/scripts/contracts/email_expire_services_to_representatives.php b/scripts/contracts/email_expire_services_to_representatives.php index 249cfc3b195..b509ecc69a4 100755 --- a/scripts/contracts/email_expire_services_to_representatives.php +++ b/scripts/contracts/email_expire_services_to_representatives.php @@ -55,14 +55,21 @@ $langs->load('main'); $langs->load('contracts'); +// Global variables +$version=DOL_VERSION; +$error=0; + + /* * Main */ +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; + $now=dol_now('tzserver'); $duration_value=$argv[2]; -$error = 0; print $script_file." launched with mode ".$mode.($duration_value?" delay=".$duration_value:"")."\n"; $sql = "SELECT DISTINCT s.nom, c.ref, cd.date_fin_validite, cd.total_ttc, p.label label, c.fk_soc,u.rowid AS uid, u.lastname, u.firstname, u.email, u.lang"; @@ -173,7 +180,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta global $conf,$langs; $newlangs=new Translate('',$conf); - $newlangs->setDefaultLang($userlang); + $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang); $newlangs->load("main"); $newlangs->load("contracts"); @@ -181,7 +188,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value); else $title= $newlangs->transnoentities("ListOfServicesToExpire"); - + $subject = "[".(empty($conf->global->MAIN_APPLICATION_TITLE)?'Dolibarr':$conf->global->MAIN_APPLICATION_TITLE)."] ".$title; $sendto = $oldemail; $from = $conf->global->MAIN_MAIL_EMAIL_FROM; diff --git a/scripts/cron/cron_run_jobs.php b/scripts/cron/cron_run_jobs.php index 151af859fcd..386c996f137 100755 --- a/scripts/cron/cron_run_jobs.php +++ b/scripts/cron/cron_run_jobs.php @@ -59,10 +59,17 @@ require_once (DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php"); require_once (DOL_DOCUMENT_ROOT.'/user/class/user.class.php'); require_once (DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php"); +// Global variables +$version=DOL_VERSION; +$error=0; + + +/* + * Main + */ -/* - * Main - */ +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; // Check security key if ($key != $conf->global->CRON_KEY) diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index 1c929dec212..23830007fae 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -45,7 +45,19 @@ require_once ($path."../../htdocs/master.inc.php"); require_once (DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php"); -$error = 0; +// Global variables +$version=DOL_VERSION; +$error=0; + + + +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; + // We get list of emailing to process diff --git a/scripts/invoices/email_unpaid_invoices_to_customers.php b/scripts/invoices/email_unpaid_invoices_to_customers.php index 1c88248b2ce..c631c394366 100755 --- a/scripts/invoices/email_unpaid_invoices_to_customers.php +++ b/scripts/invoices/email_unpaid_invoices_to_customers.php @@ -36,9 +36,9 @@ if (substr($sapi_type, 0, 3) == 'cgi') { exit; } -if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm'))) +if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts'))) { - print "Usage: $script_file [test|confirm] [delay]\n"; + print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay]\n"; print "\n"; print "Send an email to customers to remind all unpaid customer invoices.\n"; print "If you choose 'test' mode, no emails are sent.\n"; @@ -46,6 +46,7 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm exit; } $mode=$argv[1]; +$targettype=$argv[2]; require($path."../../htdocs/master.inc.php"); @@ -53,24 +54,37 @@ require_once (DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php"); $langs->load('main'); - -/* - * Main - */ +// Global variables +$version=DOL_VERSION; +$error=0; + + + +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; $now=dol_now('tzserver'); -$duration_value=$argv[2]; +$duration_value=isset($argv[3])?$argv[3]:-1; $error = 0; -print $script_file." launched with mode ".$mode.($duration_value?" delay=".$duration_value:"")."\n"; +print $script_file." launched with mode ".$mode.($duration_value>=0?" delay=".$duration_value:"")."\n"; -$sql = "SELECT f.facnumber, f.total_ttc, f.date_lim_reglement as due_date, s.nom as name, s.email, s.default_lang"; -$sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; -$sql .= " , ".MAIN_DB_PREFIX."societe as s"; -$sql .= " WHERE f.fk_statut != 0 AND f.paye = 0"; -$sql .= " AND f.fk_soc = s.rowid"; -if ($duration_value) $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; -$sql .= " ORDER BY s.email ASC, s.rowid ASC"; // Order by email to allow one message per email +$sql = "SELECT f.facnumber, f.total_ttc, f.date_lim_reglement as due_date,"; +$sql.= " s.rowid as sid, s.nom as name, s.email, s.default_lang"; +if ($targettype == 'contacts') $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail"; +$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; +if ($targettype == 'contacts') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp"; +$sql.= " WHERE f.fk_statut != 0 AND f.paye = 0"; +$sql.= " AND f.fk_soc = s.rowid"; +if ($duration_value>=0) $sql.= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; +if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc"; +$sql.= " ORDER BY"; +if ($targettype == 'contacts') $sql.= " sp.email, sp.rowid,"; +$sql.= " s.email ASC, s.rowid ASC, f.facnumber ASC"; // Order by email to allow one message per email //print $sql; $resql=$db->query($sql); @@ -78,10 +92,12 @@ if ($resql) { $num = $db->num_rows($resql); $i = 0; - $oldemail = 'none'; $olduid = 0; $oldlang=''; + $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang=''; $total = 0; $foundtoprocess = 0; - print "We found ".$num." couples (unpayed validated invoice - customer) qualified\n"; - dol_syslog("We found ".$num." couples (unpayed validated invoice - customer) qualified"); + $trackthirdpartiessent = array(); + + print "We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified\n"; + dol_syslog("We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified"); $message=''; if ($num) @@ -90,36 +106,50 @@ if ($resql) { $obj = $db->fetch_object($resql); - if (($obj->email <> $oldemail || $obj->uid <> $olduid) || $oldemail == 'none') + $newemail=empty($obj->cemail)?$obj->email:$obj->cemail; + + // Check if this record is a break after previous one + $startbreak=false; + if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true; + if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true; + if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true; + + if ($startbreak) { - // Break onto sales representative (new email or uid) - if (dol_strlen($oldemail) && $oldemail != 'none') + // Break onto sales representative (new email or cid) + if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) { - envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldcustomer); + envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget); + $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid; } else - { - if ($oldemail != 'none') print "- No email sent for ".$oldcustomer.", total: ".$total."\n"; + { + if ($oldemail != 'none') + { + if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n"; + else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n"; + } } - $oldemail = $obj->email; - $olduid = $obj->uid; + $oldemail = $newemail; + $oldsid = $obj->sid; + $oldcid = $obj->cid; $oldlang = $obj->lang; - $oldcustomer=$obj->name; + $oldtarget=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname); $message = ''; - $total = 0; + $total = 0; $foundtoprocess = 0; - $customer=$obj->name; - if (empty($obj->email)) print "Warning: Customer ".$customer." has no email. Notice disabled.\n"; + $target=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname); + //if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n"; } - if (dol_strlen($oldemail)) + if (dol_strlen($newemail)) { - $message .= $langs->trans("Invoice")." ".$obj->facnumber." : ".price($obj->total_ttc)." : ".$obj->name."\n"; - dol_syslog("email_unpaid_invoices_to_customers.php: ".$obj->email); + $message .= $langs->trans("Invoice")." ".$obj->facnumber." : ".price($obj->total_ttc)."\n"; + dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message); $foundtoprocess++; } - print "Unpaid invoice ".$obj->facnumber.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day')." customer ".$obj->name.", email ".$obj->email.": "; - if (dol_strlen($obj->email)) print "qualified."; + print "Unpaid invoice ".$obj->facnumber.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day')." customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.",":"")." email ".$newemail.": "; + if (dol_strlen($newemail)) print "qualified."; else print "disqualified (no email)."; print "\n"; @@ -131,13 +161,18 @@ if ($resql) // Si il reste des envois en buffer if ($foundtoprocess) { - if (dol_strlen($oldemail) && $oldemail != 'none') // Break onto email (new email) + if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) // Break onto email (new email) { - envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldcustomer); + envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget); + $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid; } else { - if ($oldemail != 'none') print "- No email sent for ".$oldcustomer.", total: ".$total."\n"; + if ($oldemail != 'none') + { + if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n"; + else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n"; + } } } } @@ -157,19 +192,19 @@ else * Send email * * @param string $mode Mode (test | confirm) - * @param string $oldemail Old email + * @param string $oldemail Target email * @param string $message Message to send * @param string $total Total amount of unpayed invoices * @param string $userlang Code lang to use for email output. - * @param string $oldcustomer Old customer + * @param string $oldtarget Target name * @return int <0 if KO, >0 if OK */ -function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer) +function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldtarget) { global $conf,$langs; $newlangs=new Translate('',$conf); - $newlangs->setDefaultLang($userlang); + $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang); $newlangs->load("main"); $newlangs->load("bills"); @@ -179,7 +214,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer) $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO; $msgishtml = 0; - print "- Send email for ".$oldcustomer."(".$oldemail."), total: ".$total."\n"; + print "- Send email for '".$oldtarget."' (".$oldemail."), total: ".$total."\n"; dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail); $usehtml=0; diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php index 07c181b4f93..ca260dd43bc 100755 --- a/scripts/invoices/email_unpaid_invoices_to_representatives.php +++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php @@ -54,15 +54,23 @@ require_once (DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php"); $langs->load('main'); +// Global variables +$version=DOL_VERSION; +$error=0; + + + /* * Main */ -$now=dol_now('tzserver'); -$duration_value=$argv[2]; +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; -$error = 0; -print $script_file." launched with mode ".$mode.($duration_value?" delay=".$duration_value:"")."\n"; +$now=dol_now('tzserver'); +$duration_value=isset($argv[2])?$argv[2]:-1; + +print $script_file." launched with mode ".$mode.($duration_value>=0?" delay=".$duration_value:"")."\n"; $sql = "SELECT f.facnumber, f.total_ttc, f.date_lim_reglement as due_date, s.nom as name, u.rowid as uid, u.lastname, u.firstname, u.email, u.lang"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; @@ -71,10 +79,10 @@ $sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " , ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE f.fk_statut != 0 AND f.paye = 0"; $sql .= " AND f.fk_soc = s.rowid"; -if ($duration_value) $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; +if ($duration_value>=0) $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'"; $sql .= " AND sc.fk_soc = s.rowid"; $sql .= " AND sc.fk_user = u.rowid"; -$sql .= " ORDER BY u.email ASC, s.rowid ASC"; // Order by email to allow one message per email +$sql .= " ORDER BY u.email ASC, s.rowid ASC, f.facnumber ASC"; // Order by email to allow one message per email //print $sql; $resql=$db->query($sql); @@ -138,10 +146,10 @@ if ($resql) { envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative); } - else - { - if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n"; - } + else + { + if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n"; + } } } else @@ -172,11 +180,11 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta global $conf,$langs; $newlangs=new Translate('',$conf); - $newlangs->setDefaultLang($userlang); + $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang); $newlangs->load("main"); $newlangs->load("bills"); - $subject = "[".(empty($conf->global->MAIN_APPLICATION_TITLE)?'Dolibarr':$conf->global->MAIN_APPLICATION_TITLE)."] ".$newlangs->trans("ListOfYourUnpaidInvoices"); + $subject = "[".(empty($conf->global->MAIN_APPLICATION_TITLE)?'Dolibarr':$conf->global->MAIN_APPLICATION_TITLE)."] ".$newlangs->transnoentities("ListOfYourUnpaidInvoices"); $sendto = $oldemail; $from = $conf->global->MAIN_MAIL_EMAIL_FROM; $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO; @@ -196,7 +204,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta } else { - $allmessage.= "List of unpaid invoices".($usehtml?"
\n":"\n").($usehtml?"
\n":"\n"); + $allmessage.= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml?"
\n":"\n").($usehtml?"
\n":"\n"); $allmessage.= "Note: This list contains only invoices for third parties you are linked to as a sale representative.".($usehtml?"
\n":"\n"); } $allmessage.= $message.($usehtml?"
\n":"\n"); diff --git a/scripts/invoices/rebuild_merge_pdf.php b/scripts/invoices/rebuild_merge_pdf.php index 8fc5f00334d..354b245cb23 100755 --- a/scripts/invoices/rebuild_merge_pdf.php +++ b/scripts/invoices/rebuild_merge_pdf.php @@ -50,7 +50,11 @@ $version=DOL_VERSION; $error=0; -// -------------------- START OF YOUR CODE HERE -------------------- + +/* + * Main + */ + @set_time_limit(0); print "***** ".$script_file." (".$version.") *****\n"; @@ -118,6 +122,11 @@ foreach ($argv as $key => $value) $paymentdateafter=dol_stringtotime($argv[$key+1]); $paymentdatebefore=dol_stringtotime($argv[$key+2]); + if (empty($paymentdateafter) || empty($paymentdatebefore)) + { + print 'Error: Bad date format'."\n"; + exit; + } print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day')." and ".dol_print_date($paymentdatebefore,'day').".\n"; } @@ -130,7 +139,25 @@ foreach ($argv as $key => $value) print 'Rebuild PDF for invoices with no payment done yet.'."\n"; } - if ($value == 'filter=nodeposit') + if ($value == 'filter=bank') + { + $found=true; + $option.=(empty($option)?'':'_').'bank_'.$argv[$key+1]; + $filter[]='bank'; + + $paymentonbankref=$argv[$key+1]; + $bankaccount=new Account($db); + $result=$bankaccount->fetch(0,$paymentonbankref); + if ($result <= 0) + { + print 'Error: Bank account with ref "'.$paymentonbankref.'" not found'."\n"; + exit; + } + $paymentonbankid=$bankaccount->id; + print 'Rebuild PDF for invoices with at least one payment on financial account '.$bankaccount->ref."\n"; + } + + if ($value == 'filter=nodeposit') { $found=true; $option.=(empty($option)?'':'_').'nodeposit'; @@ -169,16 +196,21 @@ if (empty($option) && count($filter) <= 0) exit; } // Check if there is no uncompatible choice -if (in_array('payments',$filter) && in_array('nopayment',$filter)) -{ - usage(); - exit; -} +if (in_array('payments',$filter) && in_array('nopayment',$filter)) +{ + usage(); + exit; +} +if (in_array('bank',$filter) && in_array('nopayment',$filter)) +{ + usage(); + exit; +} // Define SQL and SQL request to select invoices // Use $filter, $dateafterdate, datebeforedate, $paymentdateafter, $paymentdatebefore -$result=rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option); +$result=rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid); @@ -213,9 +245,11 @@ function usage() print "Rebuild PDF files for some invoices and merge PDF files into one.\n"; print "\n"; print "To build/merge PDF for invoices in a date range:\n"; - print "Usage: ".$script_file." filter=date dateafter datebefore [lang=langcode]\n"; + print "Usage: ".$script_file." filter=date dateafter datebefore\n"; print "To build/merge PDF for invoices with at least one payment in a date range:\n"; - print "Usage: ".$script_file." filter=payments dateafter datebefore [lang=langcode]\n"; + print "Usage: ".$script_file." filter=payments dateafter datebefore\n"; + print "To build/merge PDF for invoices with at least one payment onto a bank account:\n"; + print "Usage: ".$script_file." filter=bank bankref\n"; print "To build/merge PDF for all invoices, use filter=all\n"; print "Usage: ".$script_file." filter=all\n"; print "To build/merge PDF for invoices with no payments, use filter=nopayment\n"; @@ -224,9 +258,10 @@ function usage() print "To exclude replacement invoices, use filter=noreplacement\n"; print "To exclude deposit invoices, use filter=nodeposit\n"; print "To regenerate existing PDF, use regenerate=crabe\n"; + print "To generate invoices in a language, use lang=xx_XX\n"; print "\n"; print "Example: ".$script_file." filter=payments 20080101 20081231 lang=fr_FR regenerate=crabe\n"; - print "Example: ".$script_file." filter=all lang=it_IT\n"; + print "Example: ".$script_file." filter=all lang=en_US\n"; print "\n"; print "Note that some filters can be cumulated.\n"; } diff --git a/scripts/members/sync_members_dolibarr2ldap.php b/scripts/members/sync_members_dolibarr2ldap.php index eb14a9cb6a6..7a8f3bad42c 100755 --- a/scripts/members/sync_members_dolibarr2ldap.php +++ b/scripts/members/sync_members_dolibarr2ldap.php @@ -34,21 +34,24 @@ if (substr($sapi_type, 0, 3) == 'cgi') { exit; } -// Main -$version='1.11'; -$path=str_replace($script_file,'',$_SERVER["PHP_SELF"]); -@set_time_limit(0); -$error=0; - require_once($path."../../htdocs/master.inc.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); - $langs->load("main"); +// Global variables +$version=DOL_VERSION; +$error=0; -print "***** $script_file ($version) *****\n"; + + +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; if (! isset($argv[1]) || ! $argv[1]) { print "Usage: $script_file now\n"; diff --git a/scripts/members/sync_members_ldap2dolibarr.php b/scripts/members/sync_members_ldap2dolibarr.php index 6c72556f89f..45577cddcb0 100755 --- a/scripts/members/sync_members_ldap2dolibarr.php +++ b/scripts/members/sync_members_ldap2dolibarr.php @@ -34,22 +34,29 @@ if (substr($sapi_type, 0, 3) == 'cgi') { exit; } -// Main -$version='1.14'; -@set_time_limit(0); -$error=0; -$forcecommit=0; - - require_once($path."../../htdocs/master.inc.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/cotisation.class.php"); - $langs->load("main"); -$langs->load("errors"); +$langs->load("errors"); + + +// Global variables +$version=DOL_VERSION; +$error=0; +$forcecommit=0; + + + +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; // List of fields to get from LDAP $required_fields = array( diff --git a/scripts/user/sync_groups_dolibarr2ldap.php b/scripts/user/sync_groups_dolibarr2ldap.php index 5f0780e3f35..602673c8cce 100755 --- a/scripts/user/sync_groups_dolibarr2ldap.php +++ b/scripts/user/sync_groups_dolibarr2ldap.php @@ -40,17 +40,21 @@ if (! isset($argv[1]) || ! $argv[1]) { } $now=$argv[1]; -// Recupere env dolibarr -$version='1.10'; - require_once($path."../../htdocs/master.inc.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); require_once(DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"); +// Global variables +$version=DOL_VERSION; $error=0; -print "***** $script_file ($version) *****\n"; +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; /* if (! $conf->global->LDAP_SYNCHRO_ACTIVE) diff --git a/scripts/user/sync_groups_ldap2dolibarr.php b/scripts/user/sync_groups_ldap2dolibarr.php index fd92086e77f..2c239197b41 100755 --- a/scripts/user/sync_groups_ldap2dolibarr.php +++ b/scripts/user/sync_groups_ldap2dolibarr.php @@ -35,24 +35,29 @@ if (substr($sapi_type, 0, 3) == 'cgi') { exit; } +require_once($path."../../htdocs/master.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); +require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php"); +require_once(DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"); + +$langs->load("main"); +$langs->load("errors"); +// Global variables +$version=DOL_VERSION; +$error=0; +$forcecommit=0; + + +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; -// Main - -$version='1.14'; -@set_time_limit(0); -$error=0; -$forcecommit=0; - -require_once($path."../../htdocs/master.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); -require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); -require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php"); -require_once(DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"); - -$langs->load("main"); -$langs->load("errors"); // List of fields to get from LDAP $required_fields = array( @@ -136,11 +141,11 @@ if ($result >= 0) $group->entity = $conf->entity; //print_r($ldapgroup); - + if($group->id > 0) { // Group update print $langs->transnoentities("GroupUpdate").' # '.$key.': name='.$group->nom; $res=$group->update(); - + if ($res > 0) { print ' --> Updated group id='.$group->id.' name='.$group->nom; @@ -154,7 +159,7 @@ if ($result >= 0) } else { // Group creation print $langs->transnoentities("GroupCreate").' # '.$key.': name='.$group->nom; $res=$group->create(); - + if ($res > 0) { print ' --> Created group id='.$group->id.' name='.$group->nom; @@ -168,7 +173,7 @@ if ($result >= 0) } //print_r($group); - + // Gestion des utilisateurs associés au groupe // 1 - Association des utilisateurs du groupe LDAP au groupe Dolibarr $userList = array(); @@ -179,29 +184,29 @@ if ($result >= 0) $userFilter = explode(',', $userdn); $userKey = $ldap->getAttributeValues('('.$userFilter[0].')', $conf->global->LDAP_KEY_USERS); if(!is_array($userKey)) continue; - + $fuser = new User($db); - + if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { $fuser->fetch('','',$userKey[0]); // Chargement du user concerné par le SID } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { $fuser->fetch('',$userKey[0]); // Chargement du user concerné par le login } - + $userList[$userdn] = $fuser; } else { $fuser = &$userList[$userdn]; } - + $userIdList[$userdn] = $fuser->id; - + // Ajout de l'utilisateur dans le groupe if(!in_array($fuser->id, array_keys($group->members))) { $fuser->SetInGroup($group->id, $group->entity); echo $fuser->login.' added'."\n"; } } - + // 2 - Suppression des utilisateurs du groupe Dolibarr qui ne sont plus dans le groupe LDAP foreach ($group->members as $guser) { if(!in_array($guser->id, $userIdList)) { diff --git a/scripts/user/sync_users_dolibarr2ldap.php b/scripts/user/sync_users_dolibarr2ldap.php index 3b47af05053..c6a26804b40 100755 --- a/scripts/user/sync_users_dolibarr2ldap.php +++ b/scripts/user/sync_users_dolibarr2ldap.php @@ -40,17 +40,21 @@ if (! isset($argv[1]) || ! $argv[1]) { } $now=$argv[1]; -// Recupere env dolibarr -$version='1.13'; - require_once($path."../../htdocs/master.inc.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php"); +// Global variables +$version=DOL_VERSION; $error=0; -print "***** $script_file ($version) *****\n"; +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; /* if (! $conf->global->LDAP_SYNCHRO_ACTIVE) diff --git a/scripts/user/sync_users_ldap2dolibarr.php b/scripts/user/sync_users_ldap2dolibarr.php index 64bea3ca567..6f7d63c41ce 100755 --- a/scripts/user/sync_users_ldap2dolibarr.php +++ b/scripts/user/sync_users_ldap2dolibarr.php @@ -34,23 +34,27 @@ if (substr($sapi_type, 0, 3) == 'cgi') { exit; } +require_once($path."../../htdocs/master.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); +require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php"); + +$langs->load("main"); +$langs->load("errors"); + - - -// Main - -$version='1.14'; -@set_time_limit(0); +// Global variables +$version=DOL_VERSION; $error=0; $forcecommit=0; -require_once($path."../../htdocs/master.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); -require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); -require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php"); -$langs->load("main"); -$langs->load("errors"); +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; // List of fields to get from LDAP $required_fields = array( @@ -178,7 +182,7 @@ if ($result >= 0) foreach ($ldaprecords as $key => $ldapuser) { $fuser = new User($db); - + if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { $fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { @@ -226,11 +230,11 @@ if ($result >= 0) //if ($fuser->statut > 1) $fuser->statut=1; //print_r($ldapuser); - + if($fuser->id > 0) { // User update print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); $res=$fuser->update($user); - + if ($res < 0) { $error++; @@ -243,7 +247,7 @@ if ($result >= 0) } else { // User creation print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs); $res=$fuser->create($user); - + if ($res > 0) { print ' --> Created user id='.$fuser->id.' login='.$fuser->login; @@ -256,7 +260,7 @@ if ($result >= 0) } print "\n"; //print_r($fuser); - + // Gestion des groupes // TODO : revoir la gestion des groupes (ou script de sync groupes) /*if(!$error) { diff --git a/scripts/withdrawals/build_withdrawal_file.php b/scripts/withdrawals/build_withdrawal_file.php index c7513c48540..0afb79b55d7 100644 --- a/scripts/withdrawals/build_withdrawal_file.php +++ b/scripts/withdrawals/build_withdrawal_file.php @@ -34,16 +34,23 @@ if (substr($sapi_type, 0, 3) == 'cgi') { exit; } -// Recupere env dolibarr -$version='1.6'; - require_once($path."../../htdocs/master.inc.php"); require_once(DOL_DOCUMENT_ROOT."/compta/prelevement/class/bonprelevement.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/paiement/class/paiement.class.php"); -$error = 0; +// Global variables +$version=DOL_VERSION; +$error=0; + + +/* + * Main + */ + +@set_time_limit(0); +print "***** ".$script_file." (".$version.") *****\n"; $datetimeprev = time();