Ajout d'un module de droit de prêt

J'avais besoin du module "Droit de prêt" pour géréer un problématiques d'envoi de fichier de déclaration à l'organisme SOFIA via DILICOM. Afin de pouvoir dévlopper ce module, il a également été nécessaire de gérer les client par catégorie. En effet seuls les clients bibliothèque d'une librairie, distributeur ou éditeur sont concernés par cette déclaration.
This commit is contained in:
cdelambert 2007-04-30 10:50:56 +00:00
parent 0771d8ace9
commit b641ea0c2e
4 changed files with 544 additions and 0 deletions

View File

@ -0,0 +1,275 @@
<?php
/* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
*
* 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='<div class="error">'.$mailfile->error.'</div>';
echo $mesg;
}
else
{
$result=$mailfile->sendfile();
if ($result)
{
$mesg='<div class="ok">'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.</div>';
}
else
{
$mesg='<div class="error">';
if ($mailfile->error)
{
$mesg.="error";
$mesg.='<br>'.$mailfile->error;
}
else
{
$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
}
$mesg.='</div>';
}
}
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;
}
}
?>

View File

@ -0,0 +1,138 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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='<div class="error">'.$langs->trans("ErrorDate").'</div>';
}
}
/*
* 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 '<form action="index.php?action=create" method="post">';
print '<table class="border" width="100%">';
print '<tr><td>Date de début de période</td><td>';
$html->select_date($lastRapport,'d',1,1,'',"dated");
print '</td></tr>';
print '<tr><td>Date de fin de période</td><td>';
$html->select_date('','f',1,1,'',"datef");
print '</td></tr>';
print '</table>';
print '<br><center><input type="submit" class="button" value="Générer"></center>';
print '</form>';
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre"><td>Document</td>';
print '<td>Date du rapport</td>';
print '<td>Début période</td>';
print '<td>Fin période</td>';
print '<td>Nb factures</td>';
print '</tr>';
$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 '<tr '.$bc[$var].'><td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=droitpret&amp;file='.$obj->fichier.'">'.$obj->fichier.'</a></td>';
print '<td>'.$obj->date_envoie.'</td>';
print '<td>'.$obj->date_debut.'</td>';
print '<td>'.$obj->date_fin.'</td>';
print '<td>'.$obj->nbfact.'</td></tr>';
$i++;
}
}
print '</table>';
?>

View File

@ -0,0 +1,87 @@
<?php
/* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
*
* 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;
}
}
?>

View File

@ -0,0 +1,44 @@
<?php
/* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
*
* 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);
}
?>