2
0
forked from Wavyzz/dolibarr

Fix: Database compatibility

This commit is contained in:
Laurent Destailleur
2010-08-09 16:07:23 +00:00
parent 11b0d03ce0
commit d3536e3d42
10 changed files with 541 additions and 541 deletions

View File

@@ -66,10 +66,9 @@ class BoutiqueCommande
$sql.= " WHERE orders_id = ".$id; $sql.= " WHERE orders_id = ".$id;
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
if ( $result ) if ( $result )
{ {
$array = $this->db->fetch_array(); $array = $this->db->fetch_array($result);
$this->id = $array["orders_id"]; $this->id = $array["orders_id"];
$this->client_id = stripslashes($array["customers_id"]); $this->client_id = stripslashes($array["customers_id"]);

View File

@@ -29,52 +29,52 @@
* \brief Classe permettant la gestion des critiques OSCommerce * \brief Classe permettant la gestion des critiques OSCommerce
*/ */
class Critique { class Critique {
var $db ; var $db ;
var $id ; var $id ;
var $nom; var $nom;
function Critique($DB, $id=0) { function Critique($DB, $id=0) {
$this->db = $DB; $this->db = $DB;
$this->id = $id ; $this->id = $id ;
} }
/* /*
* *
* *
* *
*/ */
function fetch ($id) { function fetch ($id) {
global $conf; global $conf;
$sql = "SELECT r.reviews_id, r.reviews_rating, d.reviews_text, p.products_name"; $sql = "SELECT r.reviews_id, r.reviews_rating, d.reviews_text, p.products_name";
$sql .= " FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."reviews as r, ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."reviews_description as d"; $sql .= " FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."reviews as r, ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."reviews_description as d";
$sql .= " ,".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."products_description as p"; $sql .= " ,".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."products_description as p";
$sql .= " WHERE r.reviews_id = d.reviews_id AND r.products_id=p.products_id"; $sql .= " WHERE r.reviews_id = d.reviews_id AND r.products_id=p.products_id";
$sql .= " AND p.language_id = ".$conf->global->OSC_LANGUAGE_ID. " AND d.languages_id=".$conf->global->OSC_LANGUAGE_ID; $sql .= " AND p.language_id = ".$conf->global->OSC_LANGUAGE_ID. " AND d.languages_id=".$conf->global->OSC_LANGUAGE_ID;
$sql .= " AND r.reviews_id=$id"; $sql .= " AND r.reviews_id=$id";
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
if ( $result ) if ( $result )
{ {
$result = $this->db->fetch_array(); $result = $this->db->fetch_array($result);
$this->id = $result["reviews_id"]; $this->id = $result["reviews_id"];
$this->product_name = stripslashes($result["products_name"]); $this->product_name = stripslashes($result["products_name"]);
$this->text = stripslashes($result["reviews_text"]); $this->text = stripslashes($result["reviews_text"]);
$this->db->free(); $this->db->free($result);
} }
else else
{ {
print $this->db->error(); print $this->db->error();
print "<p>$sql"; print "<p>$sql";
} }
return $result; return $result;
} }
} }
?> ?>

View File

@@ -19,162 +19,161 @@
*/ */
class Promotion { class Promotion {
var $db ; var $db ;
var $id ; var $id ;
var $parent_id ; var $parent_id ;
var $oscid ; var $oscid ;
var $ref; var $ref;
var $titre; var $titre;
var $description; var $description;
var $price ; var $price ;
var $status ; var $status ;
function Promotion($DB, $id=0) { function Promotion($DB, $id=0) {
$this->db = $DB; $this->db = $DB;
$this->id = $id ; $this->id = $id ;
} }
/* /*
* *
* *
* *
*/ */
function create($user, $pid, $percent) { function create($user, $pid, $percent) {
global $conf; global $conf;
$sql = "SELECT products_price "; $sql = "SELECT products_price ";
$sql .= " FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."products as p"; $sql .= " FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."products as p";
$sql .= " WHERE p.products_id = $pid"; $sql .= " WHERE p.products_id = ".$pid;
$result = $this->db->query($sql) ; $result = $this->db->query($sql);
if ( $result )
{
$result = $this->db->fetch_array($result);
$this->price_init = $result["products_price"];
}
if ( $result ) $newprice = 0.95 * $this->price_init;
{
$result = $this->db->fetch_array();
$this->price_init = $result["products_price"];
}
$newprice = 0.95 * $this->price_init; $date_exp = "2003-05-01";
$date_exp = "2003-05-01"; $sql = "INSERT INTO ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."specials ";
$sql .= " (products_id, specials_new_products_price, specials_date_added, specials_last_modified, expires_date, date_status_change, status) ";
$sql .= " VALUES ($pid, $newprice, ".$this->db->idate(mktime()).", NULL, '$date_exp',NULL,1)";
$sql = "INSERT INTO ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."specials "; if ($this->db->query($sql) )
$sql .= " (products_id, specials_new_products_price, specials_date_added, specials_last_modified, expires_date, date_status_change, status) "; {
$sql .= " VALUES ($pid, $newprice, ".$this->db->idate(mktime()).", NULL, '$date_exp',NULL,1)"; $id = $this->db->last_insert_id(OSC_DB_NAME.".specials");
if ($this->db->query($sql) ) return $id;
{ }
$id = $this->db->last_insert_id(OSC_DB_NAME.".specials"); else
{
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*
*
*/
function update($id, $user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."album ";
$sql .= " SET title = '" . trim($this->titre) ."'";
$sql .= ",description = '" . trim($this->description) ."'";
return $id; $sql .= " WHERE rowid = " . $id;
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*
*
*/
function update($id, $user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."album ";
$sql .= " SET title = '" . trim($this->titre) ."'";
$sql .= ",description = '" . trim($this->description) ."'";
$sql .= " WHERE rowid = " . $id; if ( $this->db->query($sql) ) {
return 1;
} else {
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*
*
*/
function set_active($id)
{
global $conf;
if ( $this->db->query($sql) ) { $sql = "UPDATE ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."specials";
return 1; $sql .= " SET status = 1";
} else {
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*
*
*/
function set_active($id)
{
global $conf;
$sql = "UPDATE ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."specials"; $sql .= " WHERE products_id = " . $id;
$sql .= " SET status = 1";
$sql .= " WHERE products_id = " . $id; if ( $this->db->query($sql) ) {
return 1;
} else {
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*/
function set_inactive($id)
{
global $conf;
if ( $this->db->query($sql) ) { $sql = "UPDATE ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."specials";
return 1; $sql .= " SET status = 0";
} else {
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*/
function set_inactive($id)
{
global $conf;
$sql = "UPDATE ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."specials"; $sql .= " WHERE products_id = " . $id;
$sql .= " SET status = 0";
$sql .= " WHERE products_id = " . $id; if ( $this->db->query($sql) ) {
return 1;
} else {
print $this->db->error() . ' in ' . $sql;
}
}
/*
*
*
*
*/
function fetch ($id) {
global $conf;
if ( $this->db->query($sql) ) { $sql = "SELECT c.categories_id, cd.categories_name, c.parent_id";
return 1; $sql .= " FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."categories as c,".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."categories_description as cd";
} else { $sql .= " WHERE c.categories_id = cd.categories_id AND cd.language_id = ".$conf->global->OSC_LANGUAGE_ID;
print $this->db->error() . ' in ' . $sql; $sql .= " AND c.categories_id = ".$id;
} $result = $this->db->query($sql) ;
}
/*
*
*
*
*/
function fetch ($id) {
global $conf;
$sql = "SELECT c.categories_id, cd.categories_name, c.parent_id"; if ( $result ) {
$sql .= " FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."categories as c,".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."categories_description as cd"; $result = $this->db->fetch_array($result);
$sql .= " WHERE c.categories_id = cd.categories_id AND cd.language_id = ".$conf->global->OSC_LANGUAGE_ID;
$sql .= " AND c.categories_id = $id";
$result = $this->db->query($sql) ;
if ( $result ) { $this->id = $result["categories_id"];
$result = $this->db->fetch_array(); $this->parent_id = $result["parent_id"];
$this->name = $result["categories_name"];
$this->titre = $result["title"];
$this->description = $result["description"];
$this->oscid = $result["osc_id"];
}
$this->db->free($result);
$this->id = $result["categories_id"]; return $result;
$this->parent_id = $result["parent_id"]; }
$this->name = $result["categories_name"];
$this->titre = $result["title"];
$this->description = $result["description"];
$this->oscid = $result["osc_id"];
}
$this->db->free();
return $result;
}
/* /*
* *
* *
*/ */
function delete($user) { function delete($user) {
global $conf; global $conf;
$sql = "DELETE FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."products WHERE products_id = $idosc "; $sql = "DELETE FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."products WHERE products_id = $idosc ";
$sql = "DELETE FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."products_to_categories WHERE products_id = $idosc"; $sql = "DELETE FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."products_to_categories WHERE products_id = $idosc";
$sql = "DELETE FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."products_description WHERE products_id = $idosc"; $sql = "DELETE FROM ".$conf->global->OSC_DB_NAME.".".$conf->global->OSC_DB_TABLE_PREFIX."products_description WHERE products_id = $idosc";
} }
} }

View File

@@ -21,349 +21,349 @@
*/ */
/** /**
\file htdocs/compta/export/modules/compta.export.poivre.class.php \file htdocs/compta/export/modules/compta.export.poivre.class.php
\ingroup compta \ingroup compta
\brief Modele d'export compta poivre, export au format tableur \brief Modele d'export compta poivre, export au format tableur
\remarks Ce fichier doit etre utilise comme un exemple, il est specifique a une utilisation particuliere \remarks Ce fichier doit etre utilise comme un exemple, il est specifique a une utilisation particuliere
\version $Revision$ \version $Revision$
*/ */
require_once(PHP_WRITEEXCEL_PATH."/class.writeexcel_workbook.inc.php"); require_once(PHP_WRITEEXCEL_PATH."/class.writeexcel_workbook.inc.php");
require_once(PHP_WRITEEXCEL_PATH."/class.writeexcel_worksheet.inc.php"); require_once(PHP_WRITEEXCEL_PATH."/class.writeexcel_worksheet.inc.php");
/** /**
\class ComptaExportPoivre \class ComptaExportPoivre
\brief Classe permettant les exports comptables au format tableur \brief Classe permettant les exports comptables au format tableur
*/ */
class ComptaExportPoivre extends ComptaExport class ComptaExportPoivre extends ComptaExport
{ {
var $db; var $db;
var $user; var $user;
/** /**
\brief Constructeur de la class \brief Constructeur de la class
\param DB Object de base de donnees \param DB Object de base de donnees
\param USER Object utilisateur \param USER Object utilisateur
*/ */
function ComptaExportPoivre ($DB, $USER) function ComptaExportPoivre ($DB, $USER)
{ {
$this->db = $DB; $this->db = $DB;
$this->user = $USER; $this->user = $USER;
} }
/** /**
* Agregation des lignes de facture * Agregation des lignes de facture
*/ */
function Agregate($line_in) function Agregate($line_in)
{ {
dol_syslog("ComptaExportPoivre::Agregate"); dol_syslog("ComptaExportPoivre::Agregate");
dol_syslog("ComptaExportPoivre::Agregate " . sizeof($line_in) . " lignes en entrees"); dol_syslog("ComptaExportPoivre::Agregate " . sizeof($line_in) . " lignes en entrees");
$i = 0; $i = 0;
$j = 0; $j = 0;
$n = sizeof($line_in); $n = sizeof($line_in);
// On commence par la ligne 0 // On commence par la ligne 0
$this->line_out[$j] = $line_in[$i]; $this->line_out[$j] = $line_in[$i];
//print "$j ".$this->line_out[$j][8] . "<br>"; //print "$j ".$this->line_out[$j][8] . "<br>";
for ( $i = 1 ; $i < $n ; $i++) for ( $i = 1 ; $i < $n ; $i++)
{ {
// On agrege les lignes avec le meme code comptable // On agrege les lignes avec le meme code comptable
if ( ($line_in[$i][1] == $line_in[$i-1][1]) && ($line_in[$i][4] == $line_in[$i-1][4]) ) if ( ($line_in[$i][1] == $line_in[$i-1][1]) && ($line_in[$i][4] == $line_in[$i-1][4]) )
{ {
$this->line_out[$j][8] = ($this->line_out[$j][8] + $line_in[$i][8]); $this->line_out[$j][8] = ($this->line_out[$j][8] + $line_in[$i][8]);
} }
else else
{ {
$j++; $j++;
$this->line_out[$j] = $line_in[$i]; $this->line_out[$j] = $line_in[$i];
} }
} }
dol_syslog("ComptaExportPoivre::Agregate " . sizeof($this->line_out) . " lignes en sorties"); dol_syslog("ComptaExportPoivre::Agregate " . sizeof($this->line_out) . " lignes en sorties");
return 0; return 0;
} }
/** /**
* *
*/ */
function Export($dir, $linec, $linep, $id=0) function Export($dir, $linec, $linep, $id=0)
{ {
$error = 0; $error = 0;
dol_syslog("ComptaExportPoivre::Export"); dol_syslog("ComptaExportPoivre::Export");
dol_syslog("ComptaExportPoivre::Export " . sizeof($linec) . " lignes en entrees"); dol_syslog("ComptaExportPoivre::Export " . sizeof($linec) . " lignes en entrees");
$this->Agregate($linec); $this->Agregate($linec);
$this->db->begin(); $this->db->begin();
if ($id == 0) if ($id == 0)
{ {
$dt = strftime('EC%y%m', time()); $dt = strftime('EC%y%m', time());
$sql = "SELECT count(ref) FROM ".MAIN_DB_PREFIX."export_compta"; $sql = "SELECT count(ref) FROM ".MAIN_DB_PREFIX."export_compta";
$sql .= " WHERE ref like '$dt%'"; $sql .= " WHERE ref like '".$dt."%'";
if ($this->db->query($sql)) $resql=$this->db->query($sql);
if ($resql)
{
$row = $this->db->fetch_row($resql);
$cc = $row[0];
}
else
{
$error++;
dol_syslog("ComptaExportPoivre::Export Erreur Select");
}
if (!$error)
{
$this->ref = $dt . substr("000".$cc, -2);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."export_compta (ref, date_export, fk_user)";
$sql .= " VALUES ('".$this->ref."', ".$this->db->idate(mktime()).",".$this->user->id.")";
if ($this->db->query($sql))
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."export_compta");
}
else
{
$error++;
dol_syslog("ComptaExportPoivre::Export Erreur INSERT");
}
}
}
else
{
$this->id = $id;
$sql = "SELECT ref FROM ".MAIN_DB_PREFIX."export_compta";
$sql .= " WHERE rowid = ".$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
$row = $this->db->fetch_row($resql);
$this->ref = $row[0];
}
else
{
$error++;
dol_syslog("ComptaExportPoivre::Export Erreur Select");
}
}
if (!$error)
{
dol_syslog("ComptaExportPoivre::Export ref : ".$this->ref);
$fxname = $dir . "/".$this->ref.".xls";
$workbook = new writeexcel_workbook($fxname);
$page = &$workbook->addworksheet('Export');
$page->set_column(0,0,8); // A
$page->set_column(1,1,6); // B
$page->set_column(2,2,9); // C
$page->set_column(3,3,14); // D
$page->set_column(4,4,44); // E
$page->set_column(5,5,9); // F Numero de piece
$page->set_column(6,6,8); // G
// Pour les factures
// A 0 Date Operation 040604 pour 4 juin 2004
// B 1 VE -> ventilation
// C 2 code Compte general
// D 3 code client
// E 4 Intitul
// F 5 Numero de piece
// G 7 Montant
// H 8 Type operation D pour Debit ou C pour Credit
// I Date d'echeance, = a la date d'operation si pas d'echeance
// J EUR pour Monnaie en Euros
// Pour les paiements
$i = 0;
$j = 0;
$n = sizeof($this->line_out);
$oldfacture = 0;
for ( $i = 0 ; $i < $n ; $i++)
{ {
$row = $this->db->fetch_row(); if ( $oldfacture <> $this->line_out[$i][1])
$cc = $row[0]; {
} // Ligne client
else $page->write_string($j, 0, strftime("%d%m%y",$this->line_out[$i][0]));
{ $page->write_string($j, 1, "VI");
$error++; $page->write_string($j, 2, "41100000");
dol_syslog("ComptaExportPoivre::Export Erreur Select"); $page->write_string($j, 3, stripslashes($this->line_out[$i][2]));
$page->write_string($j, 4, stripslashes($this->line_out[$i][3])." Facture");
$page->write_string($j, 5, $this->line_out[$i][5]); // Numero de facture
$page->write($j, 6, price2num($this->line_out[$i][7]));
$page->write_string($j, 7, 'D' ); // D pour debit
$page->write_string($j, 8, strftime("%d%m%y",$this->line_out[$i][0]));
$j++;
// Ligne TVA
$page->write_string($j, 0, strftime("%d%m%y",$this->line_out[$i][0]));
$page->write_string($j, 1, "VI");
$page->write_string($j, 2, '4457119');
$page->write_string($j, 4, stripslashes($this->line_out[$i][3])." Facture");
$page->write_string($j, 5, $this->line_out[$i][5]); // Numero de facture
$page->write($j, 6, price2num($this->line_out[$i][6])); // Montant de TVA
$page->write_string($j, 7, 'C'); // C pour credit
$page->write_string($j, 8, strftime("%d%m%y",$this->line_out[$i][0]));
$oldfacture = $this->line_out[$i][1];
$j++;
}
$page->write_string($j, 0, strftime("%d%m%y",$this->line_out[$i][0]));
$page->write_string($j, 1, 'VI');
$page->write_string($j, 2, $this->line_out[$i][4]); // Code Comptable
$page->write_string($j, 4, $this->line_out[$i][3]." Facture");
$page->write_string($j, 5, $this->line_out[$i][5]);
$page->write($j, 6, price2num(round($this->line_out[$i][8], 2)));
$page->write_string($j, 7, 'C'); // C pour credit
$page->write_string($j, 8, strftime("%d%m%y",$this->line_out[$i][0]));
$j++;
} }
// Tag des lignes de factures
if (!$error) $n = sizeof($linec);
for ( $i = 0 ; $i < $n ; $i++)
{ {
$this->ref = $dt . substr("000".$cc, -2); $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet";
$sql .= " SET fk_export_compta=".$this->id;
$sql .= " WHERE rowid = ".$linec[$i][10];
$sql = "INSERT INTO ".MAIN_DB_PREFIX."export_compta (ref, date_export, fk_user)"; if (!$this->db->query($sql))
$sql .= " VALUES ('".$this->ref."', ".$this->db->idate(mktime()).",".$this->user->id.")"; {
$error++;
if ($this->db->query($sql)) }
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."export_compta");
}
else
{
$error++;
dol_syslog("ComptaExportPoivre::Export Erreur INSERT");
}
}
}
else
{
$this->id = $id;
$sql = "SELECT ref FROM ".MAIN_DB_PREFIX."export_compta";
$sql .= " WHERE rowid = ".$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
$row = $this->db->fetch_row($resql);
$this->ref = $row[0];
}
else
{
$error++;
dol_syslog("ComptaExportPoivre::Export Erreur Select");
}
}
if (!$error)
{
dol_syslog("ComptaExportPoivre::Export ref : ".$this->ref);
$fxname = $dir . "/".$this->ref.".xls";
$workbook = new writeexcel_workbook($fxname);
$page = &$workbook->addworksheet('Export');
$page->set_column(0,0,8); // A
$page->set_column(1,1,6); // B
$page->set_column(2,2,9); // C
$page->set_column(3,3,14); // D
$page->set_column(4,4,44); // E
$page->set_column(5,5,9); // F Numero de piece
$page->set_column(6,6,8); // G
// Pour les factures
// A 0 Date Operation 040604 pour 4 juin 2004
// B 1 VE -> ventilation
// C 2 code Compte general
// D 3 code client
// E 4 Intitul
// F 5 Numero de piece
// G 7 Montant
// H 8 Type operation D pour Debit ou C pour Credit
// I Date d'echeance, = a la date d'operation si pas d'echeance
// J EUR pour Monnaie en Euros
// Pour les paiements
$i = 0;
$j = 0;
$n = sizeof($this->line_out);
$oldfacture = 0;
for ( $i = 0 ; $i < $n ; $i++)
{
if ( $oldfacture <> $this->line_out[$i][1])
{
// Ligne client
$page->write_string($j, 0, strftime("%d%m%y",$this->line_out[$i][0]));
$page->write_string($j, 1, "VI");
$page->write_string($j, 2, "41100000");
$page->write_string($j, 3, stripslashes($this->line_out[$i][2]));
$page->write_string($j, 4, stripslashes($this->line_out[$i][3])." Facture");
$page->write_string($j, 5, $this->line_out[$i][5]); // Numero de facture
$page->write($j, 6, price2num($this->line_out[$i][7]));
$page->write_string($j, 7, 'D' ); // D pour debit
$page->write_string($j, 8, strftime("%d%m%y",$this->line_out[$i][0]));
$j++;
// Ligne TVA
$page->write_string($j, 0, strftime("%d%m%y",$this->line_out[$i][0]));
$page->write_string($j, 1, "VI");
$page->write_string($j, 2, '4457119');
$page->write_string($j, 4, stripslashes($this->line_out[$i][3])." Facture");
$page->write_string($j, 5, $this->line_out[$i][5]); // Numero de facture
$page->write($j, 6, price2num($this->line_out[$i][6])); // Montant de TVA
$page->write_string($j, 7, 'C'); // C pour credit
$page->write_string($j, 8, strftime("%d%m%y",$this->line_out[$i][0]));
$oldfacture = $this->line_out[$i][1];
$j++;
}
$page->write_string($j, 0, strftime("%d%m%y",$this->line_out[$i][0]));
$page->write_string($j, 1, 'VI');
$page->write_string($j, 2, $this->line_out[$i][4]); // Code Comptable
$page->write_string($j, 4, $this->line_out[$i][3]." Facture");
$page->write_string($j, 5, $this->line_out[$i][5]);
$page->write($j, 6, price2num(round($this->line_out[$i][8], 2)));
$page->write_string($j, 7, 'C'); // C pour credit
$page->write_string($j, 8, strftime("%d%m%y",$this->line_out[$i][0]));
$j++;
} }
// Tag des lignes de factures // Pour les paiements
$n = sizeof($linec);
for ( $i = 0 ; $i < $n ; $i++) // A Date Operation 040604 pour 4 juin 2004
// B CE -> caisse d'epargne
// C code Compte general
// D code client
// E Intitul
// F Numero de piece
// G Montant
// H Type operation D pour Debit ou C pour Credit
// I Date d'echeance, = a la date d'operation si pas d'echeance
// J EUR pour Monnaie en Euros
$i = 0;
//$j = 0;
$n = sizeof($linep);
$oldfacture = 0;
for ( $i = 0 ; $i < $n ; $i++)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet"; /*
$sql .= " SET fk_export_compta=".$this->id; * En cas de rejet ou paiement en negatif on inverse debit et credit
$sql .= " WHERE rowid = ".$linec[$i][10]; *
*
*/
if ($linep[$i][5] >= 0)
{
$debit = "D";
$credit = "C";
}
else
{
$debit = "C";
$credit = "D";
if (!$this->db->query($sql)) if ($linep[$i][6] == 'Prelevement')
{ {
$error++;
}
}
// Pour les paiements
// A Date Operation 040604 pour 4 juin 2004
// B CE -> caisse d'epargne
// C code Compte general
// D code client
// E Intitul
// F Numero de piece
// G Montant
// H Type operation D pour Debit ou C pour Credit
// I Date d'echeance, = a la date d'operation si pas d'echeance
// J EUR pour Monnaie en Euros
$i = 0;
//$j = 0;
$n = sizeof($linep);
$oldfacture = 0;
for ( $i = 0 ; $i < $n ; $i++)
{
/*
* En cas de rejet ou paiement en negatif on inverse debit et credit
*
*
*/
if ($linep[$i][5] >= 0)
{
$debit = "D";
$credit = "C";
}
else
{
$debit = "C";
$credit = "D";
if ($linep[$i][6] == 'Prelevement')
{
$linep[$i][6] = 'Rejet Prelevement'; $linep[$i][6] = 'Rejet Prelevement';
} }
} }
$page->write_string($j,0, strftime("%d%m%y",$linep[$i][0])); $page->write_string($j,0, strftime("%d%m%y",$linep[$i][0]));
$page->write_string($j,1, 'CE'); $page->write_string($j,1, 'CE');
$page->write_string($j,2, '5122000'); $page->write_string($j,2, '5122000');
if ($linep[$i][6] == 'Prelevement') if ($linep[$i][6] == 'Prelevement')
{ {
$linep[$i][6] = 'Prelevement'; $linep[$i][6] = 'Prelevement';
} }
$page->write_string($j,4, stripslashes($linep[$i][3])." ".stripslashes($linep[$i][6])); // $page->write_string($j,4, stripslashes($linep[$i][3])." ".stripslashes($linep[$i][6])); //
$page->write_string($j,5, $linep[$i][7]); // Numero de facture $page->write_string($j,5, $linep[$i][7]); // Numero de facture
$page->write($j,6, price2num(round(abs($linep[$i][5]), 2))); // Montant de la ligne $page->write($j,6, price2num(round(abs($linep[$i][5]), 2))); // Montant de la ligne
$page->write_string($j,7,$debit); $page->write_string($j,7,$debit);
$page->write_string($j,8, strftime("%d%m%y",$linep[$i][0])); $page->write_string($j,8, strftime("%d%m%y",$linep[$i][0]));
$j++; $j++;
$page->write_string($j,0, strftime("%d%m%y",$linep[$i][0])); $page->write_string($j,0, strftime("%d%m%y",$linep[$i][0]));
$page->write_string($j,1, 'CE'); $page->write_string($j,1, 'CE');
$page->write_string($j,2, '41100000'); $page->write_string($j,2, '41100000');
$page->write_string($j,3, $linep[$i][2]); $page->write_string($j,3, $linep[$i][2]);
$page->write_string($j,4, stripslashes($linep[$i][3])." ".stripslashes($linep[$i][6])); // $page->write_string($j,4, stripslashes($linep[$i][3])." ".stripslashes($linep[$i][6])); //
$page->write_string($j,5, $linep[$i][7]); // Numero de facture $page->write_string($j,5, $linep[$i][7]); // Numero de facture
$page->write($j,6, price2num(round(abs($linep[$i][5]), 2))); // Montant de la ligne $page->write($j,6, price2num(round(abs($linep[$i][5]), 2))); // Montant de la ligne
$page->write_string($j,7, $credit); $page->write_string($j,7, $credit);
$page->write_string($j,8, strftime("%d%m%y",$linep[$i][0])); $page->write_string($j,8, strftime("%d%m%y",$linep[$i][0]));
$j++; $j++;
} }
$workbook->close(); $workbook->close();
// Tag des lignes de factures // Tag des lignes de factures
$n = sizeof($linep); $n = sizeof($linep);
for ( $i = 0 ; $i < $n ; $i++) for ( $i = 0 ; $i < $n ; $i++)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."paiement"; $sql = "UPDATE ".MAIN_DB_PREFIX."paiement";
$sql .= " SET fk_export_compta=".$this->id; $sql .= " SET fk_export_compta=".$this->id;
$sql .= " WHERE rowid = ".$linep[$i][1]; $sql .= " WHERE rowid = ".$linep[$i][1];
if (!$this->db->query($sql)) if (!$this->db->query($sql))
{ {
$error++; $error++;
} }
} }
} }
if (!$error) if (!$error)
{ {
$this->db->commit(); $this->db->commit();
dol_syslog("ComptaExportPoivre::Export COMMIT"); dol_syslog("ComptaExportPoivre::Export COMMIT");
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
dol_syslog("ComptaExportPoivre::Export ROLLBACK"); dol_syslog("ComptaExportPoivre::Export ROLLBACK");
} }
return 0; return 0;
} }
} }

View File

@@ -2631,9 +2631,10 @@ class Facture extends CommonObject
$sql.= ' WHERE fk_facture = '.$this->id; $sql.= ' WHERE fk_facture = '.$this->id;
$sql.= ' AND traite = 0'; $sql.= ' AND traite = 0';
if ( $this->db->query( $sql) ) $resql=$this->db->query($sql);
if ($resql)
{ {
$row = $this->db->fetch_row(); $row = $this->db->fetch_row($resql);
if ($row[0] == 0) if ($row[0] == 0)
{ {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande';
@@ -2645,7 +2646,7 @@ class Facture extends CommonObject
$sql .= ",'".$soc->bank_account->code_guichet."'"; $sql .= ",'".$soc->bank_account->code_guichet."'";
$sql .= ",'".$soc->bank_account->number."'"; $sql .= ",'".$soc->bank_account->number."'";
$sql .= ",'".$soc->bank_account->cle_rib."')"; $sql .= ",'".$soc->bank_account->cle_rib."')";
if ( $this->db->query( $sql) ) if ( $this->db->query($sql))
{ {
return 1; return 1;
} }

View File

@@ -47,9 +47,9 @@ $h++;
if ($conf->use_preview_tabs) if ($conf->use_preview_tabs)
{ {
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/bon.php?id='.$_GET["id"]; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/bon.php?id='.$_GET["id"];
$head[$h][1] = $langs->trans("Preview"); $head[$h][1] = $langs->trans("Preview");
$h++; $h++;
} }
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/lignes.php?id='.$_GET["id"]; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/lignes.php?id='.$_GET["id"];
@@ -73,86 +73,87 @@ $prev_id = $_GET["id"];
if ($prev_id) if ($prev_id)
{ {
$bon = new BonPrelevement($db,""); $bon = new BonPrelevement($db,"");
if ($bon->fetch($_GET["id"]) == 0) if ($bon->fetch($_GET["id"]) == 0)
{
dol_fiche_head($head, $hselected, $langs->trans("WithdrawalReceipt"));
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td>'.$bon->getNomUrl(1).'</td></tr>';
print '</table>';
print '</div>';
}
else
{
print "Erreur";
}
/*
* Stats
*
*/
$sql = "SELECT sum(pl.amount), pl.statut";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
$sql.= " WHERE pl.fk_prelevement_bons = ".$prev_id;
$sql.= " GROUP BY pl.statut";
if ($db->query($sql))
{
$num = $db->num_rows();
$i = 0;
print"\n<!-- debut table -->\n";
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Status").'</td><td align="right">'.$langs->trans("Amount").'</td><td align="right">%</td></tr>';
$var=false;
while ($i < $num)
{ {
$row = $db->fetch_row(); dol_fiche_head($head, $hselected, $langs->trans("WithdrawalReceipt"));
print "<tr $bc[$var]><td>"; print '<table class="border" width="100%">';
if ($row[1] == 2) print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td>'.$bon->getNomUrl(1).'</td></tr>';
{
print $langs->trans("StatusCredited");
}
elseif ($row[1] == 3)
{
print $langs->trans("StatusRefused");
}
elseif ($row[1] == 1)
{
print $langs->trans("StatusWaiting");
}
else print $langs->trans("StatusUnknown");
print '</td><td align="right">'; print '</table>';
print price($row[0]);
print '</td><td align="right">'; print '</div>';
print round($row[0]/$bon->amount*100,2)." %"; }
print '</td>'; else
{
print "</tr>\n"; print "Erreur";
$var=!$var;
$i++;
} }
print "</table>"; /*
$db->free(); * Stats
} *
else */
{ $sql = "SELECT sum(pl.amount), pl.statut";
print $db->error() . ' ' . $sql; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
} $sql.= " WHERE pl.fk_prelevement_bons = ".$prev_id;
$sql.= " GROUP BY pl.statut";
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
print"\n<!-- debut table -->\n";
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Status").'</td><td align="right">'.$langs->trans("Amount").'</td><td align="right">%</td></tr>';
$var=false;
while ($i < $num)
{
$row = $db->fetch_row($resql);
print "<tr $bc[$var]><td>";
if ($row[1] == 2)
{
print $langs->trans("StatusCredited");
}
elseif ($row[1] == 3)
{
print $langs->trans("StatusRefused");
}
elseif ($row[1] == 1)
{
print $langs->trans("StatusWaiting");
}
else print $langs->trans("StatusUnknown");
print '</td><td align="right">';
print price($row[0]);
print '</td><td align="right">';
print round($row[0]/$bon->amount*100,2)." %";
print '</td>';
print "</tr>\n";
$var=!$var;
$i++;
}
print "</table>";
$db->free($resql);
}
else
{
print $db->error() . ' ' . $sql;
}
} }
$db->close(); $db->close();

View File

@@ -426,7 +426,7 @@ class DoliDb
\param resultset Curseur de la requete voulue \param resultset Curseur de la requete voulue
\return array \return array
*/ */
function fetch_row($resultset=0) function fetch_row($resultset)
{ {
// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
if (! is_resource($resultset)) { $resultset=$this->results; } if (! is_resource($resultset)) { $resultset=$this->results; }
@@ -439,7 +439,7 @@ class DoliDb
\param resultset Curseur de la requete voulue \param resultset Curseur de la requete voulue
\return int Nombre de lignes \return int Nombre de lignes
*/ */
function num_rows($resultset=0) function num_rows($resultset)
{ {
// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
if (! is_resource($resultset)) { $resultset=$this->results; } if (! is_resource($resultset)) { $resultset=$this->results; }

View File

@@ -421,7 +421,7 @@ class DoliDb
* \param resultset Curseur de la requete voulue * \param resultset Curseur de la requete voulue
* \return array * \return array
*/ */
function fetch_row($resultset=0) function fetch_row($resultset)
{ {
// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
if (! is_resource($resultset)) { $resultset=$this->results; } if (! is_resource($resultset)) { $resultset=$this->results; }
@@ -434,7 +434,7 @@ class DoliDb
* \param resultset Curseur de la requete voulue * \param resultset Curseur de la requete voulue
* \return int Nombre de lignes * \return int Nombre de lignes
*/ */
function num_rows($resultset=0) function num_rows($resultset)
{ {
// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
if (! is_resource($resultset)) { $resultset=$this->results; } if (! is_resource($resultset)) { $resultset=$this->results; }

View File

@@ -426,7 +426,7 @@ class DoliDb
* \param resultset Curseur de la requete voulue * \param resultset Curseur de la requete voulue
* \return array * \return array
*/ */
function fetch_row($resultset=0) function fetch_row($resultset)
{ {
// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
if (! is_bool($resultset)) if (! is_bool($resultset))
@@ -447,7 +447,7 @@ class DoliDb
* \param resultset Curseur de la requete voulue * \param resultset Curseur de la requete voulue
* \return int Nombre de lignes * \return int Nombre de lignes
*/ */
function num_rows($resultset=0) function num_rows($resultset)
{ {
// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
if (! is_object($resultset)) { $resultset=$this->results; } if (! is_object($resultset)) { $resultset=$this->results; }

View File

@@ -515,7 +515,7 @@ class DoliDb
* \param resultset Curseur de la requete voulue * \param resultset Curseur de la requete voulue
* \return array * \return array
*/ */
function fetch_row($resultset=0) function fetch_row($resultset)
{ {
// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
if (! is_resource($resultset)) { $resultset=$this->results; } if (! is_resource($resultset)) { $resultset=$this->results; }
@@ -528,7 +528,7 @@ class DoliDb
* \param resultset Curseur de la requete voulue * \param resultset Curseur de la requete voulue
* \return int Nombre de lignes * \return int Nombre de lignes
*/ */
function num_rows($resultset=0) function num_rows($resultset)
{ {
// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
if (! is_resource($resultset)) { $resultset=$this->results; } if (! is_resource($resultset)) { $resultset=$this->results; }