From 5fe70e0bee9b0db765ac644b4293aba0c65bd3af Mon Sep 17 00:00:00 2001 From: simnandez Date: Mon, 13 May 2013 17:15:23 +0200 Subject: [PATCH 01/27] Fix: Some bugs on withdrawal rejects --- ChangeLog | 1 + .../class/rejetprelevement.class.php | 4 +- htdocs/compta/prelevement/ligne.php | 57 +++++++++++++------ htdocs/langs/ca_ES/errors.lang | 1 + htdocs/langs/en_US/errors.lang | 1 + htdocs/langs/es_ES/errors.lang | 1 + htdocs/langs/fr_FR/errors.lang | 1 + 7 files changed, 46 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a6f62aacbf..9ceddc61d1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ English Dolibarr ChangeLog - 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 diff --git a/htdocs/compta/prelevement/class/rejetprelevement.class.php b/htdocs/compta/prelevement/class/rejetprelevement.class.php index a6b37df813d..543c0cdbab5 100644 --- a/htdocs/compta/prelevement/class/rejetprelevement.class.php +++ b/htdocs/compta/prelevement/class/rejetprelevement.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2010-2011 Juanjo Menent + * Copyright (C) 2010-2013 Juanjo Menent * * 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 @@ -50,7 +50,7 @@ class RejetPrelevement $this->motifs = array(); $this->facturer = array(); - $this->motifs[0] = $langs->trans("StatusMotif0"); + $this->motifs[0] = ""; //$langs->trans("StatusMotif0"); $this->motifs[1] = $langs->trans("StatusMotif1"); $this->motifs[2] = $langs->trans("StatusMotif2"); $this->motifs[3] = $langs->trans("StatusMotif3"); diff --git a/htdocs/compta/prelevement/ligne.php b/htdocs/compta/prelevement/ligne.php index d2c8c71e62a..06b147cb120 100644 --- a/htdocs/compta/prelevement/ligne.php +++ b/htdocs/compta/prelevement/ligne.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005 Rodolphe Quiedeville * Copyright (C) 2005-2012 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2010-2012 Juanjo Menent + * Copyright (C) 2010-2013 Juanjo Menent * * 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 @@ -50,29 +50,49 @@ if ($action == 'confirm_rejet') { if ( GETPOST("confirm") == 'yes') { - $daterej = mktime(2, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int')); - - $lipre = new LignePrelevement($db, $user); - - if ($lipre->fetch($id) == 0) + if (GETPOST('remonth','int')) { + $daterej = mktime(2, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int')); + } - if (GETPOST('motif','alpha') > 0 && $daterej < time()) + if (empty($daterej)) + { + $error++; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")),'errors'); + } + + elseif ($daterej > dol_now()) + { + $error++; + $langs->load("error"); + setEventMessage($langs->transnoentities("ErrorDateMustBeBeforeToday"),'errors'); + } + + if (GETPOST('motif','alpha') == 0) + { + $error++; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefusedReason")),'errors'); + } + + if ( ! $error ) + { + $lipre = new LignePrelevement($db, $user); + + if ($lipre->fetch($id) == 0) + { $rej = new RejetPrelevement($db, $user); - + $rej->create($user, $id, GETPOST('motif','alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer','int')); header("Location: ligne.php?id=".$id); exit; } - else - { - dol_syslog("Motif : ".GETPOST('motif','alpha')); - dol_syslog("$daterej $time "); - header("Location: ligne.php?id=".$id."&action=rejet"); - exit; - } + + } + else + { + $action="rejet"; } } else @@ -173,13 +193,13 @@ if ($id) print ''; //Date - print ''.$langs->trans("RefusedData").''; + print ''.$langs->trans("RefusedData").''; print ''; print $form->select_date('','','','','',"confirm_rejet"); print ''; //Reason - print ''.$langs->trans("RefusedReason").''; + print ''.$langs->trans("RefusedReason").''; print ''; print $form->selectarray("motif", $rej->motifs); print ''; @@ -303,8 +323,9 @@ if ($id) dol_print_error($db); } - $db->close(); } llxFooter(); + +$db->close(); ?> diff --git a/htdocs/langs/ca_ES/errors.lang b/htdocs/langs/ca_ES/errors.lang index 18bdab951c3..e41e6e18e6d 100644 --- a/htdocs/langs/ca_ES/errors.lang +++ b/htdocs/langs/ca_ES/errors.lang @@ -112,6 +112,7 @@ ErrorPhpCurlNotInstalled=L'extensió PHP CURL no es troba instal·lada, és indi ErrorFailedToAddToMailmanList=S'ha produït un error en intentar afegir un registre a la llista Mailman o base de dades SPIP ErrorNewVaueCantMatchOldValue=El Nou valor no pot ser igual al antic ErrorFailedToValidatePasswordReset=No s'ha pogut restablir la contrasenya. És possible que aquest enllaç ja s'hagi utilitzat (aquest enllaç només es pot utilitzar una vegada). Si no és el cas prova de reiniciar el procés de restabliment de contrasenya des del principi. +ErrorDateMustBeBeforeToday=La data no pot ser superior a avui # Warnings WarningSafeModeOnCheckExecDir=Atenció, està activada l'opció PHP safe_mode, la comanda ha d'estar dins d'un directori declarat dins del paràmetre php safe_mode_exec_dir. diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index f034287a880..31bcf96c605 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -116,6 +116,7 @@ ErrorPhpCurlNotInstalled=The PHP CURL is not installed, this is essential to tal ErrorFailedToAddToMailmanList=Failed to add record to Mailman list or SPIP base ErrorNewVaueCantMatchOldValue=New value can't be equal to old one ErrorFailedToValidatePasswordReset=Failed to reinit password. May be the reinit was already done (this link can be used only one time). If not, try to restart the reinit process. +ErrorDateMustBeBeforeToday=The date can not be greater than today # Warnings WarningMandatorySetupNotComplete=Mandatory setup parameters are not yet defined diff --git a/htdocs/langs/es_ES/errors.lang b/htdocs/langs/es_ES/errors.lang index afb31dd4269..e3f46039254 100644 --- a/htdocs/langs/es_ES/errors.lang +++ b/htdocs/langs/es_ES/errors.lang @@ -113,6 +113,7 @@ ErrorPhpCurlNotInstalled=La extensión PHP CURL no se encuentra instalada, es in ErrorFailedToAddToMailmanList=Ha ocurrido un error al intentar añadir un registro a la lista Mailman o base de datos SPIP ErrorNewVaueCantMatchOldValue=El nuevo valor no puede ser igual al antiguo ErrorFailedToValidatePasswordReset=No se ha podido restablecer la contraseña. Es posible que este enlace ya se haya utilizado (este enlace sólo puede usarse una vez). Si no es el caso, trate de reiniciar el proceso de restablecimiento de contraseña desde el principio. +ErrorDateMustBeBeforeToday=La fecha no puede ser superior a hoy # Warnings WarningMandatorySetupNotComplete=Los parámetros obligatorios de configuración no están todavía definidos diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index f683af9b736..642364fc36d 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -117,6 +117,7 @@ ErrorPhpCurlNotInstalled=L'extension PHP CURL n'est pas installée, ceci est ind ErrorFailedToAddToMailmanList=Echec de l'ajout à une liste Mailman ou base SPIP ErrorNewVaueCantMatchOldValue=La nouvelle valeur ne peut être égale à l'ancienne ErrorFailedToValidatePasswordReset=Echec de la réinitialisation du mot de passe. Il est possible que ce lien ait déjà été utilisé (l'utilisation de ce lien ne fonctionne qu'une fois). Si ce n'est pas le cas, essayer de recommencer le processus de réinit de mot de passe depuis le début. +ErrorDateMustBeBeforeToday=La date ne peut pas être supérieure à aujourd'hui # Warnings WarningMandatorySetupNotComplete=Les informations de configuration obligatoire doivent être renseignées From f9e0d03b0c1a12c5c6651f42543b3d9a16281ce0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 14 May 2013 02:46:00 +0200 Subject: [PATCH 02/27] Fix: Do not show busy if event not assigned to a user. --- htdocs/comm/action/fiche.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 551bcba826c9049667c2f2bd2f762ff0fe00f46e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 14 May 2013 10:51:09 +0200 Subject: [PATCH 03/27] Fix: Try to avoid warning --- htdocs/core/lib/company.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index aa7339cb7ca..dddc5610609 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"); From d2aacdb04bdfcd99870ca7c987f004fe98335c51 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 14 May 2013 15:58:20 +0200 Subject: [PATCH 04/27] Fix: avoid error when multiple files uploaded --- htdocs/core/tpl/ajax/fileupload_main.tpl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/tpl/ajax/fileupload_main.tpl.php b/htdocs/core/tpl/ajax/fileupload_main.tpl.php index be6906faf04..b7437af4616 100644 --- a/htdocs/core/tpl/ajax/fileupload_main.tpl.php +++ b/htdocs/core/tpl/ajax/fileupload_main.tpl.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2013 Regis Houssin * * 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 @@ -44,7 +44,7 @@ $(function () { // Events $('#fileupload').fileupload({ - completed: function (e, data) { + stop: function (e, data) { location.href=''; }, destroy: function (e, data) { From fe9e8aab5e5a11a389fe0a3fed2a65d394ee8230 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 14 May 2013 23:39:17 +0200 Subject: [PATCH 05/27] Fix: Label missing Fix: Cancel not working --- htdocs/compta/tva/fiche.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) 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 From d92b46c9f91510f8089bc952965c4331dbca70a0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 14 May 2013 23:39:17 +0200 Subject: [PATCH 06/27] Fix: Label missing Fix: Cancel not working --- htdocs/compta/tva/fiche.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) 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 From f6dfcb756c794a7b440ec43b5d87a142e167db77 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 14 May 2013 23:54:22 +0200 Subject: [PATCH 07/27] Text cells must be left align into excel 2007 export. --- htdocs/core/modules/export/export_excel2007.modules.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/modules/export/export_excel2007.modules.php b/htdocs/core/modules/export/export_excel2007.modules.php index 609bbc2d660..65fefd0d39a 100755 --- a/htdocs/core/modules/export/export_excel2007.modules.php +++ b/htdocs/core/modules/export/export_excel2007.modules.php @@ -351,6 +351,7 @@ class ExportExcel2007 extends ExportExcel $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 { From 3a11e0baadcf0385eeafbe9a2542791cba9cfbc9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 14 May 2013 23:59:59 +0200 Subject: [PATCH 08/27] New: Script export-bank-receipts should be ready for test. --- .../sociales/class/chargesociales.class.php | 1 + htdocs/fourn/class/paiementfourn.class.php | 4 +- htdocs/langs/fr_FR/compta.lang | 2 +- scripts/bank/export-bank-receipts.php | 183 +++++++++++------- 4 files changed, 115 insertions(+), 75 deletions(-) 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/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/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..72908976016 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; @@ -64,12 +68,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,7 +107,9 @@ 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); @@ -141,20 +150,23 @@ 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"), 'invoices'=>$outputlangs->transnoentitiesnoconv("Invoices"), - 'debit'=>$outputlangs->transnoentitiesnoconv("Debit"), 'credit'=>$outputlangs->transnoentitiesnoconv("Credit"), 'sold'=>$outputlangs->transnoentitiesnoconv("Solde"), 'comment'=>$outputlangs->transnoentitiesnoconv("Comment") + 'description'=>$outputlangs->transnoentitiesnoconv("Description"), 'thirdparty'=>$outputlangs->transnoentitiesnoconv("Tiers"), 'accountelem'=>$outputlangs->transnoentitiesnoconv("Piece"), + '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' + 'description'=>'description', 'thirdparty'=>'thirdparty', 'accountelem'=>'accountelem', + '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' + 'description'=>'Text', 'thirdparty'=>'Text', 'accountelem'=>'Text', + 'debit'=>'Number', 'credit'=>'Number', 'sold'=>'Number', + 'comment'=>'Text' ); // Genere en-tete @@ -184,9 +196,12 @@ if ($result >= 0) $i=0; while ($i < $numrows) { - print "Lines ".$i."\n"; - - $objp = $db->fetch_object($result); + //print "Lines ".($i+1)."\n"; + $thirdparty=''; + $accountelem=''; + $comment=''; + + $objp = $db->fetch_object($resql); $total = $total + $objp->amount; $var=!$var; @@ -203,126 +218,148 @@ if ($result >= 0) // 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; - + if ($reg[1] && $langs->trans($reg[1])!=$reg[1]) $description=$langs->trans($reg[1]); + else $description=$objp->label; + /* * Ajout les liens (societe, company...) */ - $newline=1; $links = $acct->get_url($objp->rowid); foreach($links as $key=>$val) { - 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; + $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->id=$links[$key]['url_id']; - $paymentsupplierstatic->ref=$langs->trans("Payment");; - print ' '.$paymentsupplierstatic->getNomUrl(1); - $newline=0; + $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') - { - print ''; - print ' '.img_object($langs->trans('ShowPayment'),'payment').' '; - print $langs->trans("SocialContributionPayment"); - print ''; - $newline=0; + { + $paymentsocialcontributionstatic->fetch($links[$key]['url_id']); + if ($accountelem) $accountelem.= ', '; + $accountelem.=$langs->trans("SocialContribution").' '.$paymentsocialcontributionstatic->ref; } elseif ($links[$key]['type']=='payment_vat') { - $paymentvatstatic->id=$links[$key]['url_id']; - $paymentvatstatic->ref=$langs->trans("Payment"); - print ' '.$paymentvatstatic->getNomUrl(2); + $paymentvatstatic->fetch($links[$key]['url_id']); + if ($accountelem) $accountelem.= ', '; + $accountelem.=$langs->trans("VATPayments").' '.$paymentvatstatic->ref; } - 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. + 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; - print ' ('.$langs->trans("from").' '; - print $bankstatic->getNomUrl(1,'transactions'); - print ' '.$langs->trans("toward").' '; + $comment.= ' ('.$langs->trans("from").' '; + $comment.= $bankstatic->getNomUrl(1,'transactions'); + $comment.= ' '.$langs->trans("toward").' '; $bankstatic->id=$objp->bankid; $bankstatic->label=$objp->bankref; - print $bankstatic->getNomUrl(1,''); - print ')'; + $comment.= $bankstatic->getNomUrl(1,''); + $comment.= ')'; } else { + if ($comment) $comment.= ' '; $bankstatic->id=$objp->bankid; $bankstatic->label=$objp->bankref; - print ' ('.$langs->trans("from").' '; - print $bankstatic->getNomUrl(1,''); - print ' '.$langs->trans("toward").' '; + $comment.= ' ('.$langs->trans("from").' '; + $comment.= $bankstatic->getNomUrl(1,''); + $comment.= ' '.$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 ')'; + $comment.= $bankstatic->getNomUrl(1,'transactions'); + $comment.= ')'; } } - elseif ($links[$key]['type']=='company') { - print ''; - print img_object($langs->trans('ShowCustomer'),'company').' '; - print dol_trunc($links[$key]['label'],24); - print ''; + elseif ($links[$key]['type']=='company') + { + if ($thirdparty) $thirdparty.= ', '; + $thirdparty.= dol_trunc($links[$key]['label'],24); $newline=0; } - elseif ($links[$key]['type']=='member') { - print ''; - print img_object($langs->trans('ShowMember'),'user').' '; - print $links[$key]['label']; - print ''; + elseif ($links[$key]['type']=='member') + { + if ($thirdparty) $accountelem.= ', '; + $thirdparty.= $links[$key]['label']; $newline=0; } - elseif ($links[$key]['type']=='sc') { - print ''; - print img_object($langs->trans('ShowBill'),'bill').' '; - print $langs->trans("SocialContribution"); - print ''; + /*elseif ($links[$key]['type']=='sc') + { + if ($accountelem) $accountelem.= ', '; + //$accountelem.= ''; + //$accountelem.= img_object($langs->trans('ShowBill'),'bill').' '; + $accountelem.= $langs->trans("SocialContribution"); + //$accountelem.= ''; $newline=0; } - else { - print ''; - print $links[$key]['label']; - print ''; + else + { + if ($accountelem) $accountelem.= ', '; + //$accountelem.= ''; + $accountelem.= $links[$key]['label']; + //$accountelem.= ''; $newline=0; - } + }*/ } - + $debit=$credit=''; if ($objp->amount < 0) { $totald = $totald + abs($objp->amount); - $debit=price($objp->amount * -1); + $debit=price2num($objp->amount * -1); } else { $totalc = $totalc + abs($objp->amount); - $credit=price($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; + // end of special operation processing - $objmodel->write_record($array_selected,$objp,$outputlangs,$array_export_TypeFields); + $objmodel->write_record($array_selected,$rec,$outputlangs,$array_export_TypeFields); } } else dol_print_error($db); - print "Found ".$numrows." records\n"; + print "Found ".$numrows." records for receipt ".$num."\n"; // Genere en-tete $objmodel->write_footer($outputlangs); From 64ff559a8099367e6ef9f5a75623016d48663358 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 11:24:18 +0200 Subject: [PATCH 09/27] Qual: Uniformize script headers --- scripts/bank/export-bank-receipts.php | 5 +- .../company/export-contacts-xls-example.php | 12 +++- .../company/sync_contacts_dolibarr2ldap.php | 11 +++- .../email_expire_services_to_customers.php | 15 +++-- ...ail_expire_services_to_representatives.php | 11 +++- scripts/cron/cron_run_jobs.php | 13 ++++- scripts/emailings/mailing-send.php | 14 ++++- .../email_unpaid_invoices_to_customers.php | 16 ++++-- ...ail_unpaid_invoices_to_representatives.php | 10 +++- scripts/invoices/rebuild_merge_pdf.php | 6 +- .../members/sync_members_dolibarr2ldap.php | 19 ++++--- .../members/sync_members_ldap2dolibarr.php | 25 ++++++--- scripts/user/sync_groups_dolibarr2ldap.php | 12 ++-- scripts/user/sync_groups_ldap2dolibarr.php | 55 ++++++++++--------- scripts/user/sync_users_dolibarr2ldap.php | 12 ++-- scripts/user/sync_users_ldap2dolibarr.php | 38 +++++++------ scripts/withdrawals/build_withdrawal_file.php | 15 +++-- 17 files changed, 196 insertions(+), 93 deletions(-) diff --git a/scripts/bank/export-bank-receipts.php b/scripts/bank/export-bank-receipts.php index 72908976016..88758563815 100755 --- a/scripts/bank/export-bank-receipts.php +++ b/scripts/bank/export-bank-receipts.php @@ -54,7 +54,10 @@ $error=0; -// -------------------- START OF YOUR CODE HERE -------------------- +/* + * Main + */ + @set_time_limit(0); print "***** ".$script_file." (".$version.") *****\n"; 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..09c71b571b1 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"; @@ -176,7 +183,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura $newlangs->setDefaultLang($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..282d38fb82a 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"; @@ -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..81bf16a24cf 100755 --- a/scripts/invoices/email_unpaid_invoices_to_customers.php +++ b/scripts/invoices/email_unpaid_invoices_to_customers.php @@ -53,10 +53,18 @@ 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]; diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php index 07c181b4f93..01837c47761 100755 --- a/scripts/invoices/email_unpaid_invoices_to_representatives.php +++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php @@ -54,14 +54,22 @@ require_once (DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php"); $langs->load('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]; -$error = 0; print $script_file." launched with mode ".$mode.($duration_value?" 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"; diff --git a/scripts/invoices/rebuild_merge_pdf.php b/scripts/invoices/rebuild_merge_pdf.php index 8fc5f00334d..6b13ac06849 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"; 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(); From 96dc851161e3c14d663ac4af874bdd7a2bf2594b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 13:24:18 +0200 Subject: [PATCH 10/27] Doxygen --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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') From b17fe9fc00db4b32b4ec23eea1ba69419616b65a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 13:37:31 +0200 Subject: [PATCH 11/27] New: Export support now autosize of column for excel export. Fix: Bad charset when using script export-bank-receipts. --- .../modules/export/export_csv.modules.php | 21 +- .../modules/export/export_excel.modules.php | 43 ++- .../export/export_excel2007.modules.php | 319 ------------------ .../modules/export/export_tsv.modules.php | 14 +- htdocs/exports/class/export.class.php | 2 +- scripts/bank/export-bank-receipts.php | 20 +- 6 files changed, 63 insertions(+), 356 deletions(-) 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 65fefd0d39a..6d9a585e6be 100755 --- a/htdocs/core/modules/export/export_excel2007.modules.php +++ b/htdocs/core/modules/export/export_excel2007.modules.php @@ -72,311 +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('@'); - $this->workbook->getActiveSheet()->getStyle($coord)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); - } - 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 @@ -400,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/scripts/bank/export-bank-receipts.php b/scripts/bank/export-bank-receipts.php index 88758563815..9d26dd7d126 100755 --- a/scripts/bank/export-bank-receipts.php +++ b/scripts/bank/export-bank-receipts.php @@ -176,7 +176,7 @@ if ($result >= 0) $objmodel->write_header($outputlangs); // Genere ligne de titre - $objmodel->write_title($array_fields,$array_selected,$outputlangs); + $objmodel->write_title($array_fields,$array_selected,$outputlangs,$array_export_TypeFields); // Recherche les ecritures pour le releve @@ -221,7 +221,7 @@ if ($result >= 0) // 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]) $description=$langs->trans($reg[1]); + if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) $description=$langs->transnoentitiesnoconv($reg[1]); else $description=$objp->label; /* @@ -256,13 +256,13 @@ if ($result >= 0) { $paymentsocialcontributionstatic->fetch($links[$key]['url_id']); if ($accountelem) $accountelem.= ', '; - $accountelem.=$langs->trans("SocialContribution").' '.$paymentsocialcontributionstatic->ref; + $accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref; } elseif ($links[$key]['type']=='payment_vat') { $paymentvatstatic->fetch($links[$key]['url_id']); if ($accountelem) $accountelem.= ', '; - $accountelem.=$langs->trans("VATPayments").' '.$paymentvatstatic->ref; + $accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref; } elseif ($links[$key]['type']=='banktransfert') { @@ -273,9 +273,9 @@ if ($result >= 0) $banklinestatic->fetch($links[$key]['url_id']); $bankstatic->id=$banklinestatic->fk_account; $bankstatic->label=$banklinestatic->bank_account_label; - $comment.= ' ('.$langs->trans("from").' '; + $comment.= ' ('.$langs->transnoentitiesnoconv("from").' '; $comment.= $bankstatic->getNomUrl(1,'transactions'); - $comment.= ' '.$langs->trans("toward").' '; + $comment.= ' '.$langs->transnoentitiesnoconv("toward").' '; $bankstatic->id=$objp->bankid; $bankstatic->label=$objp->bankref; $comment.= $bankstatic->getNomUrl(1,''); @@ -286,9 +286,9 @@ if ($result >= 0) if ($comment) $comment.= ' '; $bankstatic->id=$objp->bankid; $bankstatic->label=$objp->bankref; - $comment.= ' ('.$langs->trans("from").' '; + $comment.= ' ('.$langs->transnoentitiesnoconv("from").' '; $comment.= $bankstatic->getNomUrl(1,''); - $comment.= ' '.$langs->trans("toward").' '; + $comment.= ' '.$langs->transnoentitiesnoconv("toward").' '; $banklinestatic->fetch($links[$key]['url_id']); $bankstatic->id=$banklinestatic->fk_account; $bankstatic->label=$banklinestatic->bank_account_label; @@ -312,8 +312,8 @@ if ($result >= 0) { if ($accountelem) $accountelem.= ', '; //$accountelem.= ''; - //$accountelem.= img_object($langs->trans('ShowBill'),'bill').' '; - $accountelem.= $langs->trans("SocialContribution"); + //$accountelem.= img_object($langs->transnoentitiesnoconv('ShowBill'),'bill').' '; + $accountelem.= $langs->transnoentitiesnoconv("SocialContribution"); //$accountelem.= ''; $newline=0; } From e95db78d50e7fb67e7006d603e3943142dbc74f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 13:41:31 +0200 Subject: [PATCH 12/27] New: Add script export-bank-receipts. --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index ffb944785e2..064c3cd08cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ 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. For developers: - New: DolGraph can build graph with three lines. From a8e260da847769cffb118657f1792b3611698032 Mon Sep 17 00:00:00 2001 From: Grand Philippe Date: Wed, 15 May 2013 15:28:53 +0200 Subject: [PATCH 13/27] fix some language issue --- .../email_unpaid_invoices_to_representatives.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php index 8999d41604c..21bcc98e0c9 100755 --- a/scripts/invoices/email_unpaid_invoices_to_representatives.php +++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php @@ -47,7 +47,7 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm $mode=$argv[1]; -require($path."../../htdocs/master.inc.php"); +require($path."../../httpdocs/master.inc.php"); require_once (DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php"); $langs->load('main'); @@ -137,10 +137,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 @@ -175,7 +175,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta $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; @@ -195,7 +195,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"); From 2f53eacb4cefb673e8f678f404dd5b1279ae0b8c Mon Sep 17 00:00:00 2001 From: Grand Philippe Date: Wed, 15 May 2013 15:40:10 +0200 Subject: [PATCH 14/27] fix personal value error --- scripts/invoices/email_unpaid_invoices_to_representatives.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php index 21bcc98e0c9..8a0f7e8dbdf 100755 --- a/scripts/invoices/email_unpaid_invoices_to_representatives.php +++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php @@ -47,7 +47,7 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm $mode=$argv[1]; -require($path."../../httpdocs/master.inc.php"); +require($path."../../htdocs/master.inc.php"); require_once (DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php"); $langs->load('main'); From a771d3f93e16bafe345ee54bb5a6f686540a87da Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 16:42:57 +0200 Subject: [PATCH 15/27] Fix: use default lang if lang not defined --- scripts/invoices/email_unpaid_invoices_to_customers.php | 2 +- scripts/invoices/email_unpaid_invoices_to_representatives.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/invoices/email_unpaid_invoices_to_customers.php b/scripts/invoices/email_unpaid_invoices_to_customers.php index 81bf16a24cf..55a69f8cf76 100755 --- a/scripts/invoices/email_unpaid_invoices_to_customers.php +++ b/scripts/invoices/email_unpaid_invoices_to_customers.php @@ -177,7 +177,7 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer) 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"); diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php index 01837c47761..5774834e974 100755 --- a/scripts/invoices/email_unpaid_invoices_to_representatives.php +++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php @@ -180,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("bills"); From 626362780aea4f7eb8cb428ab5010a06e3adc69b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 17:30:18 +0200 Subject: [PATCH 16/27] Fix: Remove not used constant --- htdocs/admin/stock.php | 14 -------------- 1 file changed, 14 deletions(-) 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 ''; From 49735b8d39a05409b4fe05c241982b652832deef Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 17:52:56 +0200 Subject: [PATCH 17/27] New: Add option "filter=bank" onto script rebuild_merge_pdf.php to merge PDF that has one payment on a specific bank account. --- ChangeLog | 3 +- htdocs/core/lib/invoice2.lib.php | 21 ++++++++---- scripts/invoices/rebuild_merge_pdf.php | 46 ++++++++++++++++++++------ 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 064c3cd08cd..6d63d466993 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,7 +8,8 @@ For users: - 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. 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/scripts/invoices/rebuild_merge_pdf.php b/scripts/invoices/rebuild_merge_pdf.php index 6b13ac06849..712094d8295 100755 --- a/scripts/invoices/rebuild_merge_pdf.php +++ b/scripts/invoices/rebuild_merge_pdf.php @@ -134,7 +134,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].'_'.$argv[$key+2]; + $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'; @@ -173,16 +191,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); @@ -217,9 +240,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"; @@ -228,9 +253,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"; } From 011f782f23de2d961c92f3e95a6a939fb7ccebad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 18:07:34 +0200 Subject: [PATCH 18/27] Qual: Better check of parameters --- scripts/invoices/rebuild_merge_pdf.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/invoices/rebuild_merge_pdf.php b/scripts/invoices/rebuild_merge_pdf.php index 712094d8295..354b245cb23 100755 --- a/scripts/invoices/rebuild_merge_pdf.php +++ b/scripts/invoices/rebuild_merge_pdf.php @@ -122,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"; } @@ -137,7 +142,7 @@ foreach ($argv as $key => $value) if ($value == 'filter=bank') { $found=true; - $option.=(empty($option)?'':'_').'bank_'.$argv[$key+1].'_'.$argv[$key+2]; + $option.=(empty($option)?'':'_').'bank_'.$argv[$key+1]; $filter[]='bank'; $paymentonbankref=$argv[$key+1]; From 33de1340d79df8c3af4c538ee693b014f7f1d117 Mon Sep 17 00:00:00 2001 From: simnandez Date: Wed, 15 May 2013 18:11:44 +0200 Subject: [PATCH 19/27] Fix: use default lang if lang not defined --- scripts/contracts/email_expire_services_to_customers.php | 2 +- scripts/contracts/email_expire_services_to_representatives.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/contracts/email_expire_services_to_customers.php b/scripts/contracts/email_expire_services_to_customers.php index 09c71b571b1..4370314bb9d 100755 --- a/scripts/contracts/email_expire_services_to_customers.php +++ b/scripts/contracts/email_expire_services_to_customers.php @@ -180,7 +180,7 @@ 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"); diff --git a/scripts/contracts/email_expire_services_to_representatives.php b/scripts/contracts/email_expire_services_to_representatives.php index 282d38fb82a..b509ecc69a4 100755 --- a/scripts/contracts/email_expire_services_to_representatives.php +++ b/scripts/contracts/email_expire_services_to_representatives.php @@ -180,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"); From 2981d4a1ec31d6e2dd1771a8e805d5ee90f9865a Mon Sep 17 00:00:00 2001 From: simnandez Date: Wed, 15 May 2013 18:14:37 +0200 Subject: [PATCH 20/27] Fix: Remove windows CR/LF --- htdocs/compta/bank/annuel.php | 1036 ++++++++++++++++----------------- 1 file changed, 518 insertions(+), 518 deletions(-) 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(); +?> From 229ea064e9ed8be59b30f835abdac4afa35fed1f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 18:19:02 +0200 Subject: [PATCH 21/27] Can use a list of bank receipt as parameter bank receipt --- scripts/bank/export-bank-receipts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bank/export-bank-receipts.php b/scripts/bank/export-bank-receipts.php index 9d26dd7d126..08ca4a40ec9 100755 --- a/scripts/bank/export-bank-receipts.php +++ b/scripts/bank/export-bank-receipts.php @@ -185,7 +185,7 @@ if ($result >= 0) $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)."'"; + $sql.= " WHERE b.num_releve IN (".$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"; From 85eac2992596279cab8064575b0dc3ad0d621a64 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 19:30:32 +0200 Subject: [PATCH 22/27] New: Add balance before and after column --- htdocs/compta/bank/releve.php | 2 +- htdocs/langs/en_US/banks.lang | 2 + htdocs/langs/fr_FR/banks.lang | 2 + scripts/bank/export-bank-receipts.php | 492 ++++++++++++++------------ 4 files changed, 278 insertions(+), 220 deletions(-) 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/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/scripts/bank/export-bank-receipts.php b/scripts/bank/export-bank-receipts.php index 08ca4a40ec9..1d71c4edfe4 100755 --- a/scripts/bank/export-bank-receipts.php +++ b/scripts/bank/export-bank-receipts.php @@ -119,9 +119,14 @@ $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/"; @@ -141,248 +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"), 'accountelem'=>$outputlangs->transnoentitiesnoconv("Piece"), - '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', 'accountelem'=>'accountelem', - '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', 'accountelem'=>'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,$array_export_TypeFields); - - - // 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 IN (".$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+1)."\n"; - $thirdparty=''; - $accountelem=''; - $comment=''; - - $objp = $db->fetch_object($resql); - $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; + print 'Calculate start balance for receipt '.$objp->num_releve."\n"; - /* - * Ajout les liens (societe, company...) - */ - $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 ($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; - }*/ + $obj2=$db->fetch_object($resql2); + $balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0); + $db->free($resql2); + } + else + { + dol_print_error($db); + exit; } - $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; - - // end of special operation processing - $objmodel->write_record($array_selected,$rec,$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 for receipt ".$num."\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; From ff94849b0cf98e2dfba9df9a3dce28fc2cf766d9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 19:57:51 +0200 Subject: [PATCH 23/27] Fix: Security test --- htdocs/core/lib/company.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index dddc5610609..de42a730b2b 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -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; From 4fede61c16f6e97000511f9dda2aeaec2934ad91 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 20:37:50 +0200 Subject: [PATCH 24/27] Update doc --- README-FR | 25 ++++++++++++------------- README.md | 30 ++++++++++++++++-------------- 2 files changed, 28 insertions(+), 27 deletions(-) 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). From b23d15c652e050a7affdbe59d1d2fc11ca1c27c4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 22:12:03 +0200 Subject: [PATCH 25/27] New: Can send unpaid invoices to all contacts. --- .../email_unpaid_invoices_to_customers.php | 83 +++++++++++-------- 1 file changed, 49 insertions(+), 34 deletions(-) diff --git a/scripts/invoices/email_unpaid_invoices_to_customers.php b/scripts/invoices/email_unpaid_invoices_to_customers.php index 55a69f8cf76..25c375e6fcf 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"); @@ -67,18 +68,23 @@ $error=0; print "***** ".$script_file." (".$version.") *****\n"; $now=dol_now('tzserver'); -$duration_value=$argv[2]; +$duration_value=$argv[3]; $error = 0; print $script_file." launched with mode ".$mode.($duration_value?" 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) $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"; // Order by email to allow one message per email //print $sql; $resql=$db->query($sql); @@ -86,10 +92,10 @@ 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"); + 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) @@ -98,36 +104,45 @@ 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) + // Break onto sales representative (new email or cid) if (dol_strlen($oldemail) && $oldemail != 'none') { - envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldcustomer); + envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget); } else { - if ($oldemail != 'none') print "- No email sent for ".$oldcustomer.", total: ".$total."\n"; + if ($oldemail != 'none') print "- No email sent for '".$oldtarget."', total: ".$total."\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 ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.",":"")." email ".$newemail.": "; + if (dol_strlen($newemail)) print "qualified."; else print "disqualified (no email)."; print "\n"; @@ -141,11 +156,11 @@ if ($resql) { if (dol_strlen($oldemail) && $oldemail != 'none') // Break onto email (new email) { - envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldcustomer); + envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget); } else { - if ($oldemail != 'none') print "- No email sent for ".$oldcustomer.", total: ".$total."\n"; + if ($oldemail != 'none') print "- No email sent for '".$oldtarget."', total: ".$total."\n"; } } } @@ -165,14 +180,14 @@ 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; @@ -187,7 +202,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; From b05548a633c515aa824cb8d3b33d08e48312bb4a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 22:32:28 +0200 Subject: [PATCH 26/27] Fix: Parameter delay not used when set to 0 --- scripts/invoices/email_unpaid_invoices_to_customers.php | 6 +++--- .../invoices/email_unpaid_invoices_to_representatives.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/invoices/email_unpaid_invoices_to_customers.php b/scripts/invoices/email_unpaid_invoices_to_customers.php index 972cbb7d429..f616ac837ef 100755 --- a/scripts/invoices/email_unpaid_invoices_to_customers.php +++ b/scripts/invoices/email_unpaid_invoices_to_customers.php @@ -58,17 +58,17 @@ $langs->load('main'); */ $now=dol_now('tzserver'); -$duration_value=$argv[2]; +$duration_value=isset($argv[2])?$argv[2]:-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"))."'"; +if ($duration_value>=0) $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 //print $sql; diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php index 8a0f7e8dbdf..74ceed75729 100755 --- a/scripts/invoices/email_unpaid_invoices_to_representatives.php +++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php @@ -58,10 +58,10 @@ $langs->load('main'); */ $now=dol_now('tzserver'); -$duration_value=$argv[2]; +$duration_value=isset($argv[2])?$argv[2]:-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, u.rowid as uid, u.lastname, u.firstname, u.email, u.lang"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; @@ -70,7 +70,7 @@ $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 From a8187c915841f3a7c4499fce238bd0bdbae7a66b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 May 2013 23:07:43 +0200 Subject: [PATCH 27/27] Fix: Avoid duplicate emails --- .../email_unpaid_invoices_to_customers.php | 26 ++++++++++++++----- ...ail_unpaid_invoices_to_representatives.php | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/scripts/invoices/email_unpaid_invoices_to_customers.php b/scripts/invoices/email_unpaid_invoices_to_customers.php index 48eb53f4fc9..c631c394366 100755 --- a/scripts/invoices/email_unpaid_invoices_to_customers.php +++ b/scripts/invoices/email_unpaid_invoices_to_customers.php @@ -84,7 +84,7 @@ if ($duration_value>=0) $sql.= " AND f.date_lim_reglement < '".$db->idate(dol_ti 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"; // Order by email to allow one message per email +$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); @@ -94,6 +94,8 @@ if ($resql) $i = 0; $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang=''; $total = 0; $foundtoprocess = 0; + $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=''; @@ -115,13 +117,18 @@ if ($resql) if ($startbreak) { // Break onto sales representative (new email or cid) - if (dol_strlen($oldemail) && $oldemail != 'none') + if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) { envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget); + $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid; } else - { - if ($oldemail != 'none') print "- No email sent for '".$oldtarget."', 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 = $newemail; $oldsid = $obj->sid; @@ -141,7 +148,7 @@ if ($resql) 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->sid." ".$obj->name.", ".($obj->cid?"contact ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.",":"")." email ".$newemail.": "; + 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"; @@ -154,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,$oldtarget); + $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid; } else { - if ($oldemail != 'none') print "- No email sent for '".$oldtarget."', 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"; + } } } } diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php index b5c7d552752..ca260dd43bc 100755 --- a/scripts/invoices/email_unpaid_invoices_to_representatives.php +++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php @@ -82,7 +82,7 @@ $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"))."'"; $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);