From b641ea0c2e94caaaa1d8e71758679e7f4c1707a0 Mon Sep 17 00:00:00 2001 From: cdelambert Date: Mon, 30 Apr 2007 10:50:56 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20module=20de=20droit=20de=20pr?= =?UTF-8?q?=C3=AAt=20J'avais=20besoin=20du=20module=20"Droit=20de=20pr?= =?UTF-8?q?=C3=AAt"=20pour=20g=C3=A9r=C3=A9er=20un=20probl=C3=A9matiques?= =?UTF-8?q?=20d'envoi=20de=20fichier=20de=20d=C3=A9claration=20=C3=A0=20l'?= =?UTF-8?q?organisme=20SOFIA=20via=20DILICOM.=20Afin=20de=20pouvoir=20d?= =?UTF-8?q?=C3=A9vlopper=20ce=20module,=20il=20a=20=C3=A9galement=20=C3=A9?= =?UTF-8?q?t=C3=A9=20n=C3=A9cessaire=20de=20g=C3=A9rer=20les=20client=20pa?= =?UTF-8?q?r=20cat=C3=A9gorie.=20En=20effet=20seuls=20les=20clients=20bibl?= =?UTF-8?q?ioth=C3=A8que=20d'une=20librairie,=20distributeur=20ou=20=C3=A9?= =?UTF-8?q?diteur=20sont=20concern=C3=A9s=20par=20cette=20d=C3=A9claration?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/product/droitpret/droitpret.class.php | 275 ++++++++++++++++++ htdocs/product/droitpret/index.php | 138 +++++++++ .../product/droitpret/modules_droitpret.php | 87 ++++++ htdocs/product/droitpret/pre.inc.php | 44 +++ 4 files changed, 544 insertions(+) create mode 100644 htdocs/product/droitpret/droitpret.class.php create mode 100644 htdocs/product/droitpret/index.php create mode 100644 htdocs/product/droitpret/modules_droitpret.php create mode 100644 htdocs/product/droitpret/pre.inc.php diff --git a/htdocs/product/droitpret/droitpret.class.php b/htdocs/product/droitpret/droitpret.class.php new file mode 100644 index 00000000000..cc6e842b696 --- /dev/null +++ b/htdocs/product/droitpret/droitpret.class.php @@ -0,0 +1,275 @@ + + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/product/droitpret/droitpret.class.php + \ingroup pret + \brief Fichier de la classe ddes droits de prêts + \version $Revision$ +*/ + + +/** + \class DroitPret + \brief Classe permettant la gestion des droits de prets +*/ + +class DroitPret +{ + + + var $index; + var $dated; + var $datef; + var $dateEnvoie; + var $format; + var $refFile; + var $fp; + var $nbfact; + + function DroitPret($DB,$dated,$datef) + { + global $conf; + + $this->db=$DB; + $this->index = 0; + $this->dated = $dated; + $this->datef = $datef; + $this->dateEnvoie = getdate(); + $this->format = "aa"; + $this->refFile = $conf->global->MAIN_INFO_SOCIETE_GENCOD."_".date("dmY",mktime($this->dateEnvoie['hours'],$this->dateEnvoie['minutes'],$this->dateEnvoie['seconds'],$this->dateEnvoie['mon'],$this->dateEnvoie['mday'],$this->dateEnvoie['year'])).".csv"; + + + } + + function CreateNewRapport() + { + global $conf; + + $this->nbfact = 0; + + $dateEnvoie = date("Y-m-d H:i:s",mktime($this->dateEnvoie['hours'],$this->dateEnvoie['minutes'],$this->dateEnvoie['seconds'],$this->dateEnvoie['mon'],$this->dateEnvoie['mday'],$this->dateEnvoie['year'])); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."droitpret_rapport(date_envoie,format,date_debut,date_fin,fichier,nbfact) VALUES('".$dateEnvoie."','".$this->format."','".date("Y-m-d H:i:s",$this->dated)."','".date("Y-m-d H:i:s",$this->datef)."','".$this->refFile."',0)"; + $this->db->query($sql); + $lien = $conf->droitpret->dir_temp."/".$this->refFile; + + $ref = $this->db->last_insert_id(MAIN_DB_PREFIX."droitpret_rapport"); + + $this->fp = fopen($lien,"w"); + $this->WriteDEB($ref); + $this->WriteTET(); + $this->WriteFin(); + fclose($this->fp); + + $sql = "UPDATE ".MAIN_DB_PREFIX."droitpret_rapport SET nbfact = ".$this->nbfact." WHERE rowid = ".$ref; + $this->db->query($sql); + } + + function WriteDEB($ref) + { + + $dateEnvoie = date("Ymd",mktime($this->dateEnvoie['hours'],$this->dateEnvoie['minutes'],$this->dateEnvoie['seconds'],$this->dateEnvoie['mon'],$this->dateEnvoie['mday'],$this->dateEnvoie['year'])); + $ligne = "DEB".$this->ComplChar($ref,"0",8).$dateEnvoie; + $ligne .= $this->ComplChar($this->format," ",10); + fwrite($this->fp,$ligne."\n"); + + } + + function WriteTET() + { + global $conf; + + + $sql = "SELECT f.rowid, f.facnumber, f.datec, f.total_ttc, f.total "; + $sql.= "FROM llx_facture AS f, llx_facturedet AS d, llx_product AS p, llx_societe AS s, llx_categorie_societe AS c "; + $sql.= "WHERE f.fk_soc = s.idp "; + $sql.= "AND c.fk_societe = s.idp "; + $sql.= "AND d.fk_product = p.rowid "; + $sql.= "AND f.rowid = d.fk_facture "; + $sql.= "AND f.datec >= '".date("Y-m-d H:i:s",$this->dated)."' "; + $sql.= "AND f.datec < '".date("Y-m-d H:i:s",$this->datef)."' "; + $sql.= "AND c.fk_categorie = ".$conf->global->DROITPRET_CAT." "; + $sql.= "GROUP BY f.rowid"; + + $result = $this->db->query($sql); + + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + + while ($i < $num) + { + $obj = $this->db->fetch_object($result); + $ligne = "TET380".$this->ComplChar($obj->facnumber,"0",25); + $ligne.= $this->FormatDate($obj->datec); + $ligne.= $this->ComplChar("","",25).$this->ComplChar(str_replace(".","",$obj->total_ttc),"0",10); + $ligne.= $this->ComplChar(str_replace(".","",$obj->total),"0",10)."EUR"; + fwrite($this->fp,$ligne."\n"); + + $this->WriteInt($obj->rowid); + $this->WriteLin($obj->rowid); + + $this->nbfact++; + $i++; + } + } + + } + + function WriteINT($fac) + { + global $conf; + $sql = "SELECT f.rowid, s.idp "; + $sql.= "FROM llx_facture AS f, llx_societe AS s "; + $sql.= "WHERE f.fk_soc = s.idp "; + $sql.= "AND f.rowid = ".$fac." "; + + $result = $this->db->query($sql); + + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + + while ($i < $num) + { + $obj = $this->db->fetch_object($result); + $ligne = "INT".$this->ComplChar($conf->global->MAIN_INFO_SOCIETE_GENCOD,"0",13).$this->ComplChar($obj->idp,"0",13); + fwrite($this->fp,$ligne."\n"); + $i++; + } + } + + + + } + + function WriteLIN($fac) + { + $sql = "SELECT p.gencode, d.total_ttc,d.qty "; + $sql.= "FROM llx_facture AS f, llx_facturedet AS d, llx_product AS p "; + $sql.= "WHERE d.fk_product = p.rowid "; + $sql.= "AND f.rowid = d.fk_facture "; + $sql.= "AND f.rowid = ".$fac." "; + + $result = $this->db->query($sql); + + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + + while ($i < $num) + { + $obj = $this->db->fetch_object($result); + $ligne = "LIN01".$this->ComplChar($obj->gencode,"0",13); + $ligne.= $this->ComplChar(""," ",250).str_replace(".","",$obj->total_ttc); + $ligne.= $this->ComplChar($obj->qty,"0",4); + fwrite($this->fp,$ligne."\n"); + $i++; + } + } + + } + + function WriteFIN() + { + + $ligne = "FIN".$this->ComplChar($obj->nbfact,"0",8); + fwrite($this->fp,$ligne); + } + + + function EnvoiMail() + { + global $langs, $conf; + + $subject = ":::EDLFDT01".$this->ComplChar($conf->global->MAIN_INFO_SOCIETE_GENCOD,"0",13); + $sendto = $conf->global->DROITPRET_MAIL; + $from = $conf->global->MAIN_INFO_SOCIETE_MAIL; + $message = ""; + $filepath[0] = $conf->droitpret->dir_temp."/".$this->refFile; + $filename[0] = $this->refFile; + $mimetype[0] = 'text/csv'; + + $sendtocc = ""; + $deliveryreceipt = ""; + + + + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); + if ($mailfile->error) + { + $mesg='
'.$mailfile->error.'
'; + echo $mesg; + } + else + { + $result=$mailfile->sendfile(); + if ($result) + { + $mesg='
'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
'; + } + else + { + $mesg='
'; + if ($mailfile->error) + { + $mesg.="error"; + $mesg.='
'.$mailfile->error; + } + else + { + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + } + $mesg.='
'; + + } + } + return $mesg; + } + + function ComplChar($chaine,$char,$size) + { + $chaineSize=strlen ($chaine); + $ComplChar = $chaine; + for ($i = $chaineSize; $i < $size;$i++) + { + $ComplChar = $char.$ComplChar; + } + + return $ComplChar; + + } + + function FormatDate($datetime) + { + $FormatDate = str_replace("-","",$datetime); + $FormatDate = substr($FormatDate,0,8); + return $FormatDate; + } + +} + +?> \ No newline at end of file diff --git a/htdocs/product/droitpret/index.php b/htdocs/product/droitpret/index.php new file mode 100644 index 00000000000..b075cfb36b5 --- /dev/null +++ b/htdocs/product/droitpret/index.php @@ -0,0 +1,138 @@ + + * Copyright (C) 2004-2006 Laurent Destailleur + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + * + */ + +/** + \file htdocs/compta/dons/index.php + \ingroup don + \brief Page accueil espace don + \version $Revision$ +*/ + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT ."/product/droitpret/droitpret.class.php"); +require_once(DOL_DOCUMENT_ROOT ."/product/droitpret/modules_droitpret.php"); +require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php'); + + +global $conf; + +$html = new Form($db); + +if($_GET['action'] && $_GET['action'] == 'create') +{ + $dated = mktime($_POST['dhour'],$_POST['dmin'],0,$_POST['dmonth'],$_POST['dday'],$_POST['dyear']); + $datef = mktime($_POST['fhour'],$_POST['fmin'],0,$_POST['fmonth'],$_POST['fday'],$_POST['fyear']); + + if($dated < $datef) + { + $droitpret = new DroitPret($db,$dated,$datef); + $droitpret->CreateNewRapport(); + $mesg = $droitpret->EnvoiMail(); + } + else + { + $mesg='
'.$langs->trans("ErrorDate").'
'; + } + + + + + +} + + + +/* + * Affichage + */ + +llxHeader(); + +print_fiche_titre($langs->trans("DroitPretArea")); + +if ($mesg) print "$mesg\n"; + + + + +$sql = "SELECT MAX(date_fin) as lastRapport FROM ".MAIN_DB_PREFIX."droitpret_rapport"; +$result = $db->query($sql); +$obj = $db->fetch_object($result); +$lastRapport = $obj->lastRapport; + + +print '
'; + + +print ''; +print ''; +print ''; +print '
Date de début de période'; + + +$html->select_date($lastRapport,'d',1,1,'',"dated"); +print '
Date de fin de période'; +$html->select_date('','f',1,1,'',"datef"); +print '
'; + +print '
'; + +print '
'; + + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +$sql ="SELECT rowid, date_envoie, date_debut, date_fin, fichier, nbfact"; +$sql.=" FROM ".MAIN_DB_PREFIX."droitpret_rapport"; +$sql.=" ORDER BY rowid"; + +$resql = $db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + $i = 0; + $var = true; + while ($i < $num) + { + $var = !$var; + $obj = $db->fetch_object($resql); + print ''; + print ''; + print ''; + print ''; + print ''; + $i++; + } +} + + + +print '
DocumentDate du rapportDébut périodeFin périodeNb factures
'.$obj->fichier.''.$obj->date_envoie.''.$obj->date_debut.''.$obj->date_fin.''.$obj->nbfact.'
'; + +?> diff --git a/htdocs/product/droitpret/modules_droitpret.php b/htdocs/product/droitpret/modules_droitpret.php new file mode 100644 index 00000000000..ba11284b155 --- /dev/null +++ b/htdocs/product/droitpret/modules_droitpret.php @@ -0,0 +1,87 @@ + + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/product/droitpret/modules_droipret.php + \ingroup droitpret + \brief Fichier contenant la classe mère de generation des exports de droits de prets + \version $Revision$ +*/ + + +/** + \class ModeleDroitPret + \brief Classe mère des modèles de format d'export de droits de prêts +*/ + +class ModeleDroitPret +{ + + + /** + * \brief Constructeur + */ + function ModeleDroitPret() + { + } + + /** + * \brief Charge en memoire et renvoie la liste des modèles actifs + * \param db Handler de base + */ + function liste_rapport($db) + { + + $liste=array(); + $sql ="SELECT rowid, fichier"; + $sql.=" FROM ".MAIN_DB_PREFIX."droitpret_rapport"; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $liste[$row[0]]=$row[1]; + $i++; + } + } + else + { + dolibarr_print_error($db); + return -1; + } + + return $liste; + } + + + + + + +} + + +?> diff --git a/htdocs/product/droitpret/pre.inc.php b/htdocs/product/droitpret/pre.inc.php new file mode 100644 index 00000000000..36786c9b6b5 --- /dev/null +++ b/htdocs/product/droitpret/pre.inc.php @@ -0,0 +1,44 @@ + + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/compta/droitpret/pre.inc.php + \ingroup pret + \brief Fichier gestionnaire du menu de gauche de l'espace droitpret + \version $Revision$ +*/ + +require("../../main.inc.php"); + +function llxHeader($head = "", $title="", $help_url='') +{ + global $langs; + + top_menu($head, $title); + + $menu = new Menu(); + + + + left_menu($menu->liste, $help_url); +} + +?>