diff -BNaur '--exclude=CVS' '--exclude=*.patch' '--exclude=.#*' '--exclude=*~' '--exclude=*.rej' '--exclude=*.orig' '--exclude=*.bak' '--exclude=conf.php' '--exclude=documents' ./dolibarr-snapshot/htdocs//compta/journal/class/journal.class.php ./dolibarr-dev/htdocs//compta/journal/class/journal.class.php --- ./dolibarr-snapshot/htdocs//compta/journal/class/journal.class.php 1970-01-01 01:00:00.000000000 +0100 +++ ./dolibarr-dev/htdocs//compta/journal/class/journal.class.php 2011-10-03 18:01:09.000000000 +0200 @@ -0,0 +1,174 @@ + + * + * 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. + */ + +/** + * \file htdocs/compta/class/journal.class.php + * \ingroup compta + * \brief Fichier de la classe des journaux comptable + * \version $Id:journal.class.php,v 1.0 2011/10/01 14:42:22 DTux Exp $ + */ + + +/** \class journal + * \brief Classe permettant l'édition des journaux comptables + */ + +class Journal +{ + var $db ; + var $date; + var $n_piece; + var $n_facture; + var $compte; + var $type; + var $debit; + var $credit; + var $ligne = array(); + + +/** + * \brief Constructeur de la classe + * \param DB handler acces base de donnees **/ + + function Journal($DB) + { + global $langs; + $this->db = $DB; + $this->date = $langs->trans("Date"); + $this->n_piece = html_entity_decode($langs->trans("Piece"),3,'UTF-8'); + $this->n_facture = html_entity_decode($langs->trans("InvoiceRef"),3,'UTF-8'); + $this->compte = html_entity_decode($langs->trans("Account"),3,'UTF-8'); + $this->type = html_entity_decode($langs->trans("Type"),3,'UTF-8'); + $this->debit = html_entity_decode($langs->trans("Debit"),3,'UTF-8'); + $this->credit = html_entity_decode($langs->trans("Credit"),3,'UTF-8'); + + } + + function JournalLoad($sql) + { + global $langs,$bc; + $tabfac = array(); + $tabht = array(); + $tabtva = array(); + $tabttc = array(); + $url = array(); + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i=0; + $resligne=array(); + $invoicestatic=new Facture($db); + while ($i < $num) + { + $obj = $this->db->fetch_object($result); + // les variables + $cptcli = (! empty($conf->global->COMPTA_ACCOUNT_CUSTOMER))?$conf->global->COMPTA_ACCOUNT_CUSTOMER:$langs->trans("CodeNotDef"); + $compta_soc = (! empty($obj->code_compta))?$obj->code_compta:$cptcli; + $compta_prod = $obj->accountancy_code_sell; + if (empty($compta_prod)) + { + if($obj->product_type == 0) $compta_prod = (! empty($conf->global->COMPTA_PRODUCT_SOLD_ACCOUNT))?$conf->global->COMPTA_PRODUCT_SOLD_ACCOUNT:$langs->trans("CodeNotDef") ; + else $compta_prod = (! empty($conf->global->COMPTA_SERVICE_SOLD_ACCOUNT))?$conf->global->COMPTA_SERVICE_SOLD_ACCOUNT:$langs->trans("CodeNotDef") ; + } + $cpttva = (! empty($conf->global->COMPTA_VAT_ACCOUNT))?$conf->global->COMPTA_VAT_ACCOUNT:$langs->trans("CodeNotDef"); + $compta_tva = (! empty($obj->accountancy_code))?$obj->accountancy_code:$cpttva; + + //la ligne facture + $invoicestatic->id=$obj->rowid; + $invoicestatic->ref=$obj->facnumber; + $tabfac[$obj->rowid]["client"] = $obj->nom; + $tabfac[$obj->rowid]["url"] = $invoicestatic->getNomUrl(1); + $tabfac[$obj->rowid]["date"] = $obj->datef; + $tabfac[$obj->rowid]["ref"] = $obj->facnumber; + $tabfac[$obj->rowid]["type"] = $obj->type; + $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc; + $tabht[$obj->rowid][$compta_prod] += $obj->total_ht; + $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva; + $i++; + } + $var = TRUE; + $i = 0; //numéro de ligne + $piece = 1; //numero de piece + foreach ($tabfac as $key => $val) + { + + $date_a = substr($val["date"],8,2) . '/' . substr($val["date"],5,2) .'/'. substr($val["date"],0,4); + + + foreach ($tabttc[$key] as $k => $mt) + { + $this->JournalLigne($i, $val, $date_a, $k, $langs->trans("ThirdParty"), $mt); + $i++; + } + + foreach ($tabht[$key] as $k => $mt) + { + if ($mt) + { + $this->JournalLigne($i, $val, $date_a, $k, $langs->trans("Products"), -$mt); + $i++; + + } + } + // vat + //var_dump($tabtva); + foreach ($tabtva[$key] as $k => $mt) + { + if ($mt) + { + $this->JournalLigne($i, $val, $date_a, $k, $langs->trans("VAT"), -$mt); + $i++; + } + } + $var = !$var; + $i++; + } + //$this->db->close(); + /**foreach($this->ligne as $n_ligne => $val) + { + foreach($val as $key => $val2) + { + echo "key :".$key." val :".$val2."
"; + } + }**/ + + + + }else + { + dol_syslog("ComptaJournal::Create Erreur $result SELECT Mysql"); + } + + + } + function JournalLigne($i, $val, $date_a, $k, $type, $mt) + { + $this->ligne[$i]->libelle = html_entity_decode($val["ref"] . " ". $val["client"],3,'UTF-8'); + $this->ligne[$i]->n_piece = $val["ref"]; + $this->ligne[$i]->date = $date_a; + $this->ligne[$i]->url = $val["url"]; + $this->ligne[$i]->compte = html_entity_decode($k,3,'UTF-8'); + $this->ligne[$i]->type = html_entity_decode($type,3,'UTF-8'); + $this->ligne[$i]->debit = ($mt>=0?$mt:''); + $this->ligne[$i]->credit = ($mt<0?-$mt:''); + } + + +} +?> \ Pas de fin de ligne à la fin du fichier. diff -BNaur '--exclude=CVS' '--exclude=*.patch' '--exclude=.#*' '--exclude=*~' '--exclude=*.rej' '--exclude=*.orig' '--exclude=*.bak' '--exclude=conf.php' '--exclude=documents' ./dolibarr-snapshot/htdocs//compta/journal/class/journalexport_csv.class.php ./dolibarr-dev/htdocs//compta/journal/class/journalexport_csv.class.php --- ./dolibarr-snapshot/htdocs//compta/journal/class/journalexport_csv.class.php 1970-01-01 01:00:00.000000000 +0100 +++ ./dolibarr-dev/htdocs//compta/journal/class/journalexport_csv.class.php 2011-10-03 17:22:21.000000000 +0200 @@ -0,0 +1,88 @@ + + * + * 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. + */ + + /** + * \file htdocs/compta/class/journalexport_csv.class.php + * \ingroup compta + * \brief Classe d'exportation des journaux comptable + * \version $Id:journal.class.php,v 1.0 2011/10/01 14:42:22 DTux Exp $ + */ + + + /** \class journal + * \brief Classe permettant l'édition des journaux comptables + */ + + + class JournalExport + { + function JournalExport($journal,$db) + { + $this->entete($journal); + $this->ligne($journal); + $this->finexport($journal); + } + + + // génère l'entête de fichier + function entete() + { + global $langs, $date, $year, $month, $nom; + header("Content-Type: text/csv"); + header('Content-Disposition: attachment; filename=' . $year . ($month < 10 ? "0".$month : $month) . "_" . str_replace(" ","_",$nom).".csv"); + + header('Last-Modified: '. $date . ' GMT'); + header('Expires: ' . $date); + //header specifique IE :s parce que sinon il aime pas + if(preg_match('/msie|(microsoft internet explorer)/i', $_SERVER['HTTP_USER_AGENT'])) + { + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + }else + { + header('Pragma: no-cache'); + } + print '"'.$langs->trans("Date").'","'.html_entity_decode($langs->trans("Piece"),3,'UTF-8').' ('.html_entity_decode($langs->trans("InvoiceRef"),3,'UTF-8').')","'; + print html_entity_decode($langs->trans("Account"),3,'UTF-8').'","'; + print html_entity_decode($langs->trans("Wording"),3,'UTF-8').'","'; + print html_entity_decode($langs->trans("Type"),3,'UTF-8').'","'.html_entity_decode($langs->trans("Debit"),3,'UTF-8').'","'.html_entity_decode($langs->trans("Credit"),3,'UTF-8').'"'; + print "\n"; + } + + + function ligne($journal) + { + foreach($journal->ligne as $val) + { + print '"'.$val->date.'","'; + print $val->n_piece . '","'; + print $val->compte .'","'; + print $val->libelle .'","'; + print $val->type .'",'; + print $val->debit .','; + print $val->credit ."\n"; + } + } + + function finexport($journal) + { + } + + +} +?> \ Pas de fin de ligne à la fin du fichier. diff -BNaur '--exclude=CVS' '--exclude=*.patch' '--exclude=.#*' '--exclude=*~' '--exclude=*.rej' '--exclude=*.orig' '--exclude=*.bak' '--exclude=conf.php' '--exclude=documents' ./dolibarr-snapshot/htdocs//compta/journal/sellsjournal.php ./dolibarr-dev/htdocs//compta/journal/sellsjournal.php --- ./dolibarr-snapshot/htdocs//compta/journal/sellsjournal.php 2011-10-06 09:38:47.000000000 +0200 +++ ./dolibarr-dev/htdocs//compta/journal/sellsjournal.php 2011-10-10 14:38:30.799280749 +0200 @@ -26,6 +26,9 @@ require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php"); require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); +require_once(DOL_DOCUMENT_ROOT ."/compta/journal/class/journal.class.php"); +//require_once(DOL_DOCUMENT_ROOT ."/compta/class/journalmodules.class.php"); + $langs->load("companies"); @@ -37,6 +40,8 @@ { accessforbidden(); } +$nom=$langs->trans("SellsJournal"); +//$nomlink=; /******************************************************************* @@ -58,7 +63,10 @@ // Put here content of your page // ... +$builddate=time(); +$description=$langs->trans("DescSellsJournal"); +$exportlink=dol_buildpath("/compta/journal/sellsjournal.php"); $year_current = strftime("%Y",dol_now()); $pastmonth = strftime("%m",dol_now()) - 1; $pastmonthyear = $year_current; @@ -68,18 +76,45 @@ $pastmonthyear--; } -$date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); -$date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]); +if ($_REQUEST["yearid"] != NULL) +{ + $year=$_REQUEST["yearid"]; +}else +{ + $year=$year_current; +} + + +if ($_REQUEST["monthid"] != NULL) +{ + //echo "monthid non nul"; + $month=$_REQUEST["monthid"]; + $date_start=dol_get_first_day($year,$month); + $date_end=dol_get_last_day($year,$month); + +}else +{ + //echo "monthid nul"; + $month=$pastmonth; + $date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); + $date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]); + if (isset($_REQUEST["date_startyear"])) + { + $year=$_REQUEST["date_startyear"]; + } + +} + if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - $date_start=dol_get_first_day($pastmonthyear,$pastmonth,false); $date_end=dol_get_last_day($pastmonthyear,$pastmonth,false); + $date_start=dol_get_first_day($pastmonthyear,$pastmonth,false); + $date_end=dol_get_last_day($pastmonthyear,$pastmonth,false); } $nom=$langs->trans("SellsJournal"); //$nomlink=; -$builddate=time(); -$description=$langs->trans("DescSellsJournal"); + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); @@ -87,7 +122,7 @@ $idpays = $p[0]; $sql = "SELECT f.rowid, f.facnumber, f.type, f.datef, f.ref_client , fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.total_ttc,"; -$sql .= " p.accountancy_code_sell, s.code_compta , ct.accountancy_code"; +$sql .= " p.accountancy_code_sell, s.code_compta , s.nom , ct.accountancy_code"; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet fd "; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product p ON p.rowid = fd.fk_product "; $sql .= " JOIN ".MAIN_DB_PREFIX."facture f ON f.rowid = fd.fk_facture "; @@ -95,47 +130,58 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '".$idpays."'"; $sql .= " WHERE f.fk_statut > 0 AND f.entity IN (0,".$conf->entity.")"; if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; -$sql .= " order by f.rowid"; - -$result = $db->query($sql); -if ($result) +$sql .= " order by f.datef"; +$journal = new Journal($db); +$journal->JournalLoad($sql); +if ($_REQUEST["action"] == $langs->trans("Export")) { - $tabfac = array(); - $tabht = array(); - $tabtva = array(); - $tabttc = array(); - - $num = $db->num_rows($result); - $i=0; - $resligne=array(); - while ($i < $num) - { - $obj = $db->fetch_object($result); - // les variables - $cptcli = (! empty($conf->global->COMPTA_ACCOUNT_CUSTOMER))?$conf->global->COMPTA_ACCOUNT_CUSTOMER:$langs->trans("CodeNotDef"); - $compta_soc = (! empty($obj->code_compta))?$obj->code_compta:$cptcli; - $compta_prod = $obj->accountancy_code_sell; - if (empty($compta_prod)) - { - if($obj->product_type == 0) $compta_prod = (! empty($conf->global->COMPTA_PRODUCT_SOLD_ACCOUNT))?$conf->global->COMPTA_PRODUCT_SOLD_ACCOUNT:$langs->trans("CodeNotDef"); - else $compta_prod = (! empty($conf->global->COMPTA_SERVICE_SOLD_ACCOUNT))?$conf->global->COMPTA_SERVICE_SOLD_ACCOUNT:$langs->trans("CodeNotDef"); - } - $cpttva = (! empty($conf->global->COMPTA_VAT_ACCOUNT))?$conf->global->COMPTA_VAT_ACCOUNT:$langs->trans("CodeNotDef"); - $compta_tva = (! empty($obj->accountancy_code))?$obj->accountancy_code:$cpttva; - - //la ligne facture - $tabfac[$obj->rowid]["date"] = $obj->datef; - $tabfac[$obj->rowid]["ref"] = $obj->facnumber; - $tabfac[$obj->rowid]["type"] = $obj->type; - $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc; - $tabht[$obj->rowid][$compta_prod] += $obj->total_ht; - $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva; + + $export = TRUE; + /**$format_export = $_REQUEST["export_format"]; + echo $format_export;**/ + //date actuelle + $date = gmdate('D, d M Y H:i:s'); + + /**switch($format_export) + { + case "csv": + {**/ + include_once(DOL_DOCUMENT_ROOT ."/compta/journal/class/journalexport_csv.class.php"); + //} + + $export = new JournalExport($journal,$db); + //} +}else +{ + llxHeader('','',''); + $html=new Form($db); + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1) . "ou choisissez un mois et une année" . $html->select_month($month,'monthid',0 ,1) . "-" . $html->select_year($year,'yearid',0, 10, 0, 1); + report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); + $i = 0; + print ""; + print ""; + //print ""; + print '"; + print '"; + print ""; + print ""; + + + $r=''; + foreach($journal->ligne as $val) + { + print "\n"; + //print "".$k."".$langs->trans("ThirdParty").""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } - $i++; - } -} -else { - dol_print_error($db); } diff -BNaur '--exclude=CVS' '--exclude=*.patch' '--exclude=.#*' '--exclude=*~' '--exclude=*.rej' '--exclude=*.orig' '--exclude=*.bak' '--exclude=conf.php' '--exclude=documents' ./dolibarr-snapshot/htdocs//core/class/html.form.class.php ./dolibarr-dev/htdocs//core/class/html.form.class.php --- ./dolibarr-snapshot/htdocs//core/class/html.form.class.php 2011-10-10 05:00:07.000000000 +0200 +++ ./dolibarr-dev/htdocs//core/class/html.form.class.php 2011-10-10 14:28:35.708970432 +0200 @@ -3222,6 +3222,83 @@ return; } + + /** + * \brief Return HTML combo list of month + * \param selected Preselected value + * \param htmlname Nom de la zone select + * \param useempty Affiche valeur vide dans liste + * TODO Move into html.formother + */ + function select_month($selected='',$htmlname='monthid',$useempty=0, $nooutput=0) + { + $month = monthArrayOrSelected(-1); // Get array + + $select_month = ''; + if ($nooutput != 1) + { + print $select_month; + } + return $select_month; + } + + /** + * \brief Return HTML combo list of years + * \param selected Preselected value (''=current year, -1=none, year otherwise) + * \param htmlname Name of HTML select object + * \param useempty Affiche valeur vide dans liste + * \param $min_year Offset of minimum year into list (by default current year -10) + * \param $max_year Offset of maximum year into list (by default current year + 5) + * TODO Move into html.formother + */ + function select_year($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $nooutput=0) + { + $currentyear = date("Y"); + $max_year = $currentyear+$max_year; + $min_year = $currentyear-$min_year; + if(empty($selected)) $selected = $currentyear; + + $output= '\n"; + if ($nooutput != 1) + { + print $output; + } + return $output; + } + + + + + /** * Function to show a form to select a duration on a page * diff -BNaur '--exclude=CVS' '--exclude=*.patch' '--exclude=.#*' '--exclude=*~' '--exclude=*.rej' '--exclude=*.orig' '--exclude=*.bak' '--exclude=conf.php' '--exclude=documents' ./dolibarr-snapshot/htdocs//langs/fr_FR/compta.lang ./dolibarr-dev/htdocs//langs/fr_FR/compta.lang --- ./dolibarr-snapshot/htdocs//langs/fr_FR/compta.lang 2011-10-06 09:38:21.000000000 +0200 +++ ./dolibarr-dev/htdocs//langs/fr_FR/compta.lang 2011-10-10 14:21:22.574186231 +0200 @@ -79,6 +79,7 @@ ByThirdParties=Par tiers ByUserAuthorOfInvoice=Par auteur de la facture AccountancyExport=Export comptable +Export=Exporter ErrorWrongAccountancyCodeForCompany=Code compta client incorrect pour %s SuppliersProductsSellSalesTurnover=Chiffre d'affaires généré par la vente des produits des fournisseurs CheckReceipt=Bordereau de remise de chèques diff -BNaur '--exclude=CVS' '--exclude=*.patch' '--exclude=.#*' '--exclude=*~' '--exclude=*.rej' '--exclude=*.orig' '--exclude=*.bak' '--exclude=conf.php' '--exclude=documents' ./dolibarr-snapshot/htdocs//lib/report.lib.php ./dolibarr-dev/htdocs//lib/report.lib.php --- ./dolibarr-snapshot/htdocs//lib/report.lib.php 2011-10-06 09:38:47.000000000 +0200 +++ ./dolibarr-dev/htdocs//lib/report.lib.php 2011-10-10 14:17:56.338144035 +0200 @@ -32,7 +32,7 @@ * @param builddate Date generation * @param exportlink Link for export or '' */ -function report_header($nom,$variante='',$period,$periodlink,$description,$builddate,$exportlink='') +function report_header($nom,$variante='',$period,$periodlink,$description,$builddate,$exportlink='',$exportbutton='') { global $langs; @@ -75,14 +75,19 @@ // Ligne d'export print ''; print ''; - if (! $exportlink) print ''; + print ''; + print ''; + + print ''; + print ''; + if ($exportlink) + { + print ''; + } + - print ''; - print ''; print ''; print '
".$langs->trans("JournalNum")."'.$langs->trans("Date").''.$langs->trans("Piece").' ('.$langs->trans("InvoiceRef").")'.$langs->trans("Account")."".$langs->trans("Wording")."".$langs->trans("Type")."".$langs->trans("Debit")."".$langs->trans("Credit")."
".($mt>=0?$mt:'')."".($mt<0?-$mt:'')."'.$val->date.''.$val->n_piece . ''.$val->compte .''.$val->libelle .''.$val->type .''.$val->debit .''.$val->credit .'
'.$langs->trans("GeneratedOn").''; - else print ''; - print dol_print_date($builddate); - if ($exportlink) print ''.$langs->trans("Export").''.$exportlink; - print '
' . dol_print_date($builddate) .'
'; + print ''; + print '
';