Qual: Ne charge la classe Notify et Adresse que si besoin
This commit is contained in:
parent
8be79ef68a
commit
d896fd9484
@ -20,6 +20,9 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT ."/address.class.php");
|
||||||
|
|
||||||
|
|
||||||
class Commande {
|
class Commande {
|
||||||
var $db ;
|
var $db ;
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,536 +18,519 @@
|
|||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
* $Source$
|
* $Source$
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
\file htdocs/compta/facture/facture-rec.class.php
|
\file htdocs/compta/facture/facture-rec.class.php
|
||||||
\ingroup facture
|
\ingroup facture
|
||||||
\brief Fichier de la classe des factures recurentes
|
\brief Fichier de la classe des factures recurentes
|
||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
|
||||||
|
|
||||||
/*! \class FactureRec
|
|
||||||
|
/**
|
||||||
|
\class FactureRec
|
||||||
\brief Classe de gestion des factures recurrentes
|
\brief Classe de gestion des factures recurrentes
|
||||||
*/
|
*/
|
||||||
class FactureRec
|
class FactureRec
|
||||||
{
|
{
|
||||||
var $id;
|
var $id;
|
||||||
var $db;
|
var $db;
|
||||||
var $socidp;
|
var $socidp;
|
||||||
var $number;
|
var $number;
|
||||||
var $author;
|
var $author;
|
||||||
var $date;
|
var $date;
|
||||||
var $ref;
|
var $ref;
|
||||||
var $amount;
|
var $amount;
|
||||||
var $remise;
|
var $remise;
|
||||||
var $tva;
|
var $tva;
|
||||||
var $total;
|
var $total;
|
||||||
var $note;
|
var $note;
|
||||||
var $db_table;
|
var $db_table;
|
||||||
var $propalid;
|
var $propalid;
|
||||||
var $projetid;
|
var $projetid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialisation de la class
|
* Initialisation de la class
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function FactureRec($DB, $facid=0)
|
function FactureRec($DB, $facid=0)
|
||||||
{
|
|
||||||
$this->db = $DB ;
|
|
||||||
$this->facid = $facid;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Créé la facture
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function create($user)
|
|
||||||
{
|
{
|
||||||
/*
|
$this->db = $DB ;
|
||||||
*
|
$this->facid = $facid;
|
||||||
*/
|
}
|
||||||
$facsrc = new Facture($this->db);
|
/**
|
||||||
|
* Créé la facture
|
||||||
|
*/
|
||||||
|
function create($user)
|
||||||
|
{
|
||||||
|
$facsrc = new Facture($this->db);
|
||||||
|
|
||||||
if ($facsrc->fetch($this->facid) > 0)
|
if ($facsrc->fetch($this->facid) > 0)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* On positionne en mode brouillon la facture
|
* On positionne en mode brouillon la facture
|
||||||
*/
|
*/
|
||||||
$this->brouillon = 1;
|
$this->brouillon = 1;
|
||||||
if (! $facsrc->projetid)
|
if (! $facsrc->projetid)
|
||||||
{
|
{
|
||||||
$facsrc->projetid = "NULL";
|
$facsrc->projetid = "NULL";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (titre, fk_soc, datec, amount, remise, remise_percent, note, fk_user_author,fk_projet, fk_cond_reglement) ";
|
||||||
*
|
$sql .= " VALUES ('$this->titre', '$facsrc->socidp', now(), '$facsrc->amount', '$facsrc->remise', '$facsrc->remise_percent', '$this->note','$user->id', '$facsrc->projetid', '$facsrc->cond_reglement_id')";
|
||||||
*/
|
if ( $this->db->query($sql) )
|
||||||
|
{
|
||||||
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (titre, fk_soc, datec, amount, remise, remise_percent, note, fk_user_author,fk_projet, fk_cond_reglement) ";
|
/*
|
||||||
$sql .= " VALUES ('$this->titre', '$facsrc->socidp', now(), '$facsrc->amount', '$facsrc->remise', '$facsrc->remise_percent', '$this->note','$user->id', '$facsrc->projetid', '$facsrc->cond_reglement_id')";
|
* Produits
|
||||||
if ( $this->db->query($sql) )
|
*/
|
||||||
{
|
for ($i = 0 ; $i < sizeof($facsrc->lignes) ; $i++)
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
|
{
|
||||||
|
if ($facsrc->lignes[$i]->produit_id > 0)
|
||||||
/*
|
{
|
||||||
* Produits
|
$prod = new Product($this->db);
|
||||||
*
|
$prod->fetch($facsrc->lignes[$i]->produit_id);
|
||||||
*/
|
}
|
||||||
for ($i = 0 ; $i < sizeof($facsrc->lignes) ; $i++)
|
|
||||||
{
|
|
||||||
if ($facsrc->lignes[$i]->produit_id > 0)
|
|
||||||
{
|
|
||||||
$prod = new Product($this->db);
|
|
||||||
$prod->fetch($facsrc->lignes[$i]->produit_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$result_insert = $this->addline($this->id,
|
$result_insert = $this->addline($this->id,
|
||||||
addslashes($facsrc->lignes[$i]->desc),
|
addslashes($facsrc->lignes[$i]->desc),
|
||||||
$facsrc->lignes[$i]->subprice,
|
$facsrc->lignes[$i]->subprice,
|
||||||
$facsrc->lignes[$i]->qty,
|
$facsrc->lignes[$i]->qty,
|
||||||
$facsrc->lignes[$i]->tva_taux,
|
$facsrc->lignes[$i]->tva_taux,
|
||||||
$facsrc->lignes[$i]->produit_id,
|
$facsrc->lignes[$i]->produit_id,
|
||||||
$facsrc->lignes[$i]->remise_percent);
|
$facsrc->lignes[$i]->remise_percent);
|
||||||
|
|
||||||
|
|
||||||
if ( $result_insert < 0)
|
if ( $result_insert < 0)
|
||||||
{
|
{
|
||||||
print '<br>' . $this->db->error() .'<br>';
|
print '<br>' . $this->db->error() .'<br>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print $this->db->error() . '<b><br>'.$sql;
|
print $this->db->error() . '<b><br>'.$sql;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recupére l'objet facture
|
* Recupére l'objet facture
|
||||||
*
|
*/
|
||||||
*
|
function fetch($rowid, $societe_id=0)
|
||||||
*/
|
|
||||||
function fetch($rowid, $societe_id=0)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
$sql = "SELECT f.fk_soc,f.titre,f.amount,f.tva,f.total,f.total_ttc,f.remise,f.remise_percent,f.fk_projet, c.rowid as crid, c.libelle, c.libelle_facture, f.note, f.fk_user_author";
|
$sql = "SELECT f.fk_soc,f.titre,f.amount,f.tva,f.total,f.total_ttc,f.remise,f.remise_percent,f.fk_projet, c.rowid as crid, c.libelle, c.libelle_facture, f.note, f.fk_user_author";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture_rec as f, ".MAIN_DB_PREFIX."cond_reglement as c";
|
$sql .= " FROM ".MAIN_DB_PREFIX."facture_rec as f, ".MAIN_DB_PREFIX."cond_reglement as c";
|
||||||
$sql .= " WHERE f.rowid=$rowid AND c.rowid = f.fk_cond_reglement";
|
$sql .= " WHERE f.rowid=$rowid AND c.rowid = f.fk_cond_reglement";
|
||||||
|
|
||||||
if ($societe_id > 0)
|
if ($societe_id > 0)
|
||||||
{
|
{
|
||||||
$sql .= " AND f.fk_soc = ".$societe_id;
|
$sql .= " AND f.fk_soc = ".$societe_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
if ($this->db->num_rows())
|
if ($this->db->num_rows())
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object();
|
$obj = $this->db->fetch_object();
|
||||||
|
|
||||||
$this->id = $rowid;
|
$this->id = $rowid;
|
||||||
$this->datep = $obj->dp;
|
$this->datep = $obj->dp;
|
||||||
$this->titre = $obj->titre;
|
$this->titre = $obj->titre;
|
||||||
$this->amount = $obj->amount;
|
$this->amount = $obj->amount;
|
||||||
$this->remise = $obj->remise;
|
$this->remise = $obj->remise;
|
||||||
$this->total_ht = $obj->total;
|
$this->total_ht = $obj->total;
|
||||||
$this->total_tva = $obj->tva;
|
$this->total_tva = $obj->tva;
|
||||||
$this->total_ttc = $obj->total_ttc;
|
$this->total_ttc = $obj->total_ttc;
|
||||||
$this->paye = $obj->paye;
|
$this->paye = $obj->paye;
|
||||||
$this->remise_percent = $obj->remise_percent;
|
$this->remise_percent = $obj->remise_percent;
|
||||||
$this->socidp = $obj->fk_soc;
|
$this->socidp = $obj->fk_soc;
|
||||||
$this->statut = $obj->fk_statut;
|
$this->statut = $obj->fk_statut;
|
||||||
$this->date_lim_reglement = $obj->dlr;
|
$this->date_lim_reglement = $obj->dlr;
|
||||||
$this->cond_reglement_id = $obj->crid;
|
$this->cond_reglement_id = $obj->crid;
|
||||||
$this->cond_reglement = $obj->libelle;
|
$this->cond_reglement = $obj->libelle;
|
||||||
$this->cond_reglement_facture = $obj->libelle_facture;
|
$this->cond_reglement_facture = $obj->libelle_facture;
|
||||||
$this->projetid = $obj->fk_projet;
|
$this->projetid = $obj->fk_projet;
|
||||||
$this->note = stripslashes($obj->note);
|
$this->note = stripslashes($obj->note);
|
||||||
$this->user_author = $obj->fk_user_author;
|
$this->user_author = $obj->fk_user_author;
|
||||||
$this->lignes = array();
|
$this->lignes = array();
|
||||||
|
|
||||||
if ($this->statut == 0)
|
if ($this->statut == 0)
|
||||||
{
|
{
|
||||||
$this->brouillon = 1;
|
$this->brouillon = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->free();
|
$this->db->free();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lignes
|
* Lignes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql = "SELECT l.fk_product,l.description, l.subprice, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent";
|
$sql = "SELECT l.fk_product,l.description, l.subprice, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet_rec as l WHERE l.fk_facture = ".$this->id." ORDER BY l.rowid ASC";
|
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet_rec as l WHERE l.fk_facture = ".$this->id." ORDER BY l.rowid ASC";
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$num = $this->db->num_rows();
|
$num = $this->db->num_rows();
|
||||||
$i = 0; $total = 0;
|
$i = 0; $total = 0;
|
||||||
|
|
||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$objp = $this->db->fetch_object($result);
|
$objp = $this->db->fetch_object($result);
|
||||||
$faclig = new FactureLigne($this->db);
|
$faclig = new FactureLigne($this->db);
|
||||||
$faclig->produit_id = $objp->fk_product;
|
$faclig->produit_id = $objp->fk_product;
|
||||||
$faclig->desc = stripslashes($objp->description);
|
$faclig->desc = stripslashes($objp->description);
|
||||||
$faclig->qty = $objp->qty;
|
$faclig->qty = $objp->qty;
|
||||||
$faclig->price = $objp->price;
|
$faclig->price = $objp->price;
|
||||||
$faclig->subprice = $objp->subprice;
|
$faclig->subprice = $objp->subprice;
|
||||||
$faclig->tva_taux = $objp->tva_taux;
|
$faclig->tva_taux = $objp->tva_taux;
|
||||||
$faclig->remise_percent = $objp->remise_percent;
|
$faclig->remise_percent = $objp->remise_percent;
|
||||||
$this->lignes[$i] = $faclig;
|
$this->lignes[$i] = $faclig;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->free();
|
$this->db->free();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print $this->db->error();
|
print $this->db->error();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "Error";
|
print "Error";
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print $this->db->error();
|
print $this->db->error();
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Recupére l'objet client lié à la facture
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function fetch_client()
|
|
||||||
{
|
|
||||||
$client = new Societe($this->db);
|
|
||||||
$client->fetch($this->socidp);
|
|
||||||
$this->client = $client;
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Valide la facture
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function valid($userid, $dir)
|
|
||||||
{
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid";
|
|
||||||
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print $this->db->error() . ' in ' . $sql;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supprime la facture
|
* Recupére l'objet client lié à la facture
|
||||||
*
|
*/
|
||||||
*/
|
function fetch_client()
|
||||||
function delete($rowid)
|
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = $rowid;";
|
$client = new Societe($this->db);
|
||||||
|
$client->fetch($this->socidp);
|
||||||
|
$this->client = $client;
|
||||||
|
|
||||||
if ($this->db->query( $sql) )
|
|
||||||
{
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = $rowid";
|
|
||||||
|
|
||||||
if ($this->db->query( $sql) )
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "Err : ".$this->db->error();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "Err : ".$this->db->error();
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Valide la facture
|
/**
|
||||||
*
|
* Valide la facture
|
||||||
*/
|
*/
|
||||||
function set_valid($rowid, $user, $soc)
|
function valid($userid, $dir)
|
||||||
{
|
{
|
||||||
if ($this->brouillon)
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid";
|
||||||
{
|
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
||||||
$action_notify = 2; // ne pas modifier cette valeur
|
|
||||||
|
|
||||||
$numfa = facture_get_num($soc); // définit dans includes/modules/facture
|
if ($this->db->query($sql) )
|
||||||
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture set facnumber='$numfa', fk_statut = 1, fk_user_valid = $user->id WHERE rowid = $rowid ;";
|
return 1;
|
||||||
$result = $this->db->query( $sql);
|
}
|
||||||
|
else
|
||||||
/*
|
{
|
||||||
* Notify
|
print $this->db->error() . ' in ' . $sql;
|
||||||
*
|
}
|
||||||
*/
|
|
||||||
$forbidden_chars=array("/","\\",":","*","?","\"","<",">","|","[","]",",",";","=");
|
|
||||||
$facref = str_replace($forbidden_chars,"_",$this->ref);
|
|
||||||
$filepdf = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf";
|
|
||||||
|
|
||||||
|
|
||||||
$mesg = "La facture ".$this->ref." a été validée.\n";
|
|
||||||
|
|
||||||
$notify = New Notify($this->db);
|
|
||||||
$notify->send($action_notify, $this->socidp, $mesg, "facture", $rowid, $filepdf);
|
|
||||||
/*
|
|
||||||
* Update Stats
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$sql = "SELECT fk_product FROM ".MAIN_DB_PREFIX."facturedet WHERE fk_facture = ".$this->id;
|
|
||||||
$sql .= " AND fk_product IS NOT NULL";
|
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
|
||||||
|
|
||||||
if ($result)
|
|
||||||
{
|
|
||||||
$num = $this->db->num_rows();
|
|
||||||
$i = 0;
|
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $this->db->fetch_object($result);
|
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET nbvente=nbvente+1 WHERE rowid = ".$obj->fk_product;
|
|
||||||
$db2 = $this->db->dbclone();
|
|
||||||
$result = $db2->query($sql);
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Contrats
|
|
||||||
*/
|
|
||||||
$contrat = new Contrat($this->db);
|
|
||||||
$contrat->create_from_facture($this->id, $user, $this->socidp);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Ajoute un produit dans la facture
|
/**
|
||||||
*
|
* Supprime la facture
|
||||||
*/
|
*/
|
||||||
function add_product($idproduct, $qty, $remise_percent)
|
function delete($rowid)
|
||||||
{
|
{
|
||||||
if ($idproduct > 0)
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = $rowid;";
|
||||||
{
|
|
||||||
$i = sizeof($this->products);
|
if ($this->db->query( $sql) )
|
||||||
$this->products[$i] = $idproduct;
|
{
|
||||||
if (!$qty)
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = $rowid";
|
||||||
{
|
|
||||||
$qty = 1 ;
|
if ($this->db->query( $sql) )
|
||||||
}
|
{
|
||||||
$this->products_qty[$i] = $qty;
|
return 1;
|
||||||
$this->products_remise_percent[$i] = $remise_percent;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
print "Err : ".$this->db->error();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "Err : ".$this->db->error();
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Ajoute une ligne de facture
|
/**
|
||||||
*
|
* Valide la facture
|
||||||
*/
|
*/
|
||||||
function addline($facid, $desc, $pu, $qty, $txtva, $fk_product='NULL', $remise_percent=0)
|
function set_valid($rowid, $user, $soc)
|
||||||
{
|
{
|
||||||
if ($this->brouillon)
|
if ($this->brouillon)
|
||||||
{
|
{
|
||||||
if (strlen(trim($qty))==0)
|
$action_notify = 2; // ne pas modifier cette valeur
|
||||||
{
|
|
||||||
$qty=1;
|
|
||||||
}
|
|
||||||
$remise = 0;
|
|
||||||
$price = round(ereg_replace(",",".",$pu), 2);
|
|
||||||
$subprice = $price;
|
|
||||||
if (trim(strlen($remise_percent)) > 0)
|
|
||||||
{
|
|
||||||
$remise = round(($pu * $remise_percent / 100), 2);
|
|
||||||
$price = $pu - $remise;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (fk_facture,description,price,qty,tva_taux, fk_product, remise_percent, subprice, remise)";
|
$numfa = facture_get_num($soc); // définit dans includes/modules/facture
|
||||||
$sql .= " VALUES ('$facid', '$desc', '$price', '$qty', '$txtva', '$fk_product', '$remise_percent', '$subprice', '$remise') ;";
|
|
||||||
|
|
||||||
if ( $this->db->query( $sql) )
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facture set facnumber='$numfa', fk_statut = 1, fk_user_valid = $user->id WHERE rowid = $rowid ;";
|
||||||
{
|
$result = $this->db->query( $sql);
|
||||||
$this->updateprice($facid);
|
|
||||||
return 1;
|
/*
|
||||||
}
|
* Notify
|
||||||
else
|
*/
|
||||||
{
|
$forbidden_chars=array("/","\\",":","*","?","\"","<",">","|","[","]",",",";","=");
|
||||||
print "$sql";
|
$facref = str_replace($forbidden_chars,"_",$this->ref);
|
||||||
return -1;
|
$filepdf = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf";
|
||||||
}
|
|
||||||
}
|
|
||||||
|
$mesg = "La facture ".$this->ref." a été validée.\n";
|
||||||
|
|
||||||
|
$notify = New Notify($this->db);
|
||||||
|
$notify->send($action_notify, $this->socidp, $mesg, "facture", $rowid, $filepdf);
|
||||||
|
/*
|
||||||
|
* Update Stats
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$sql = "SELECT fk_product FROM ".MAIN_DB_PREFIX."facturedet WHERE fk_facture = ".$this->id;
|
||||||
|
$sql .= " AND fk_product IS NOT NULL";
|
||||||
|
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
$num = $this->db->num_rows();
|
||||||
|
$i = 0;
|
||||||
|
while ($i < $num)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET nbvente=nbvente+1 WHERE rowid = ".$obj->fk_product;
|
||||||
|
$db2 = $this->db->dbclone();
|
||||||
|
$result = $db2->query($sql);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Contrats
|
||||||
|
*/
|
||||||
|
$contrat = new Contrat($this->db);
|
||||||
|
$contrat->create_from_facture($this->id, $user, $this->socidp);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Mets à jour une ligne de facture
|
/**
|
||||||
*
|
* Ajoute un produit dans la facture
|
||||||
*/
|
*/
|
||||||
function updateline($rowid, $desc, $pu, $qty, $remise_percent=0)
|
function add_product($idproduct, $qty, $remise_percent)
|
||||||
{
|
{
|
||||||
if ($this->brouillon)
|
if ($idproduct > 0)
|
||||||
{
|
{
|
||||||
if (strlen(trim($qty))==0)
|
$i = sizeof($this->products);
|
||||||
{
|
$this->products[$i] = $idproduct;
|
||||||
$qty=1;
|
if (!$qty)
|
||||||
}
|
{
|
||||||
$remise = 0;
|
$qty = 1 ;
|
||||||
$price = round(ereg_replace(",",".",$pu), 2);
|
}
|
||||||
$subprice = $price;
|
$this->products_qty[$i] = $qty;
|
||||||
if (trim(strlen($remise_percent)) > 0)
|
$this->products_remise_percent[$i] = $remise_percent;
|
||||||
{
|
}
|
||||||
$remise = round(($pu * $remise_percent / 100), 2);
|
|
||||||
$price = $pu - $remise;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$remise_percent=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set description='$desc',price=$price,subprice=$subprice,remise=$remise,remise_percent=$remise_percent,qty=$qty WHERE rowid = $rowid ;";
|
|
||||||
$result = $this->db->query( $sql);
|
|
||||||
|
|
||||||
$this->updateprice($this->id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Supprime une ligne
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function deleteline($rowid)
|
|
||||||
{
|
|
||||||
if ($this->brouillon)
|
|
||||||
{
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = $rowid;";
|
|
||||||
$result = $this->db->query( $sql);
|
|
||||||
|
|
||||||
$this->updateprice($this->id);
|
/**
|
||||||
}
|
* Ajoute une ligne de facture
|
||||||
|
*/
|
||||||
|
function addline($facid, $desc, $pu, $qty, $txtva, $fk_product='NULL', $remise_percent=0)
|
||||||
|
{
|
||||||
|
if ($this->brouillon)
|
||||||
|
{
|
||||||
|
if (strlen(trim($qty))==0)
|
||||||
|
{
|
||||||
|
$qty=1;
|
||||||
|
}
|
||||||
|
$remise = 0;
|
||||||
|
$price = round(ereg_replace(",",".",$pu), 2);
|
||||||
|
$subprice = $price;
|
||||||
|
if (trim(strlen($remise_percent)) > 0)
|
||||||
|
{
|
||||||
|
$remise = round(($pu * $remise_percent / 100), 2);
|
||||||
|
$price = $pu - $remise;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (fk_facture,description,price,qty,tva_taux, fk_product, remise_percent, subprice, remise)";
|
||||||
|
$sql .= " VALUES ('$facid', '$desc', '$price', '$qty', '$txtva', '$fk_product', '$remise_percent', '$subprice', '$remise') ;";
|
||||||
|
|
||||||
|
if ( $this->db->query( $sql) )
|
||||||
|
{
|
||||||
|
$this->updateprice($facid);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "$sql";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Mise à jour des sommes de la facture
|
/**
|
||||||
*
|
* Mets à jour une ligne de facture
|
||||||
*/
|
*/
|
||||||
function updateprice($facid)
|
function updateline($rowid, $desc, $pu, $qty, $remise_percent=0)
|
||||||
{
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
|
if ($this->brouillon)
|
||||||
$err=0;
|
{
|
||||||
$sql = "SELECT price, qty, tva_taux FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = $facid;";
|
if (strlen(trim($qty))==0)
|
||||||
|
{
|
||||||
|
$qty=1;
|
||||||
|
}
|
||||||
|
$remise = 0;
|
||||||
|
$price = round(ereg_replace(",",".",$pu), 2);
|
||||||
|
$subprice = $price;
|
||||||
|
if (trim(strlen($remise_percent)) > 0)
|
||||||
|
{
|
||||||
|
$remise = round(($pu * $remise_percent / 100), 2);
|
||||||
|
$price = $pu - $remise;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$remise_percent=0;
|
||||||
|
}
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set description='$desc',price=$price,subprice=$subprice,remise=$remise,remise_percent=$remise_percent,qty=$qty WHERE rowid = $rowid ;";
|
||||||
|
$result = $this->db->query( $sql);
|
||||||
|
|
||||||
if ($result)
|
$this->updateprice($this->id);
|
||||||
{
|
}
|
||||||
$num = $this->db->num_rows();
|
|
||||||
$i = 0;
|
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $this->db->fetch_object($result);
|
|
||||||
|
|
||||||
$products[$i][0] = $obj->price;
|
|
||||||
$products[$i][1] = $obj->qty;
|
|
||||||
$products[$i][2] = $obj->tva_taux;
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->db->free();
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
$calculs = calcul_price($products, $this->remise_percent);
|
|
||||||
|
|
||||||
$this->total_remise = $calculs[3];
|
|
||||||
$this->amount_ht = $calculs[4];
|
|
||||||
$this->total_ht = $calculs[0];
|
|
||||||
$this->total_tva = $calculs[1];
|
|
||||||
$this->total_ttc = $calculs[2];
|
|
||||||
$tvas = $calculs[5];
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec SET amount = $this->amount_ht, remise=$this->total_remise, total=$this->total_ht, tva=$this->total_tva, total_ttc=$this->total_ttc";
|
|
||||||
$sql .= " WHERE rowid = $facid ;";
|
|
||||||
|
|
||||||
if ( $this->db->query($sql) )
|
|
||||||
{
|
|
||||||
if ($err == 0)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "$sql<br>";
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "Error";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Applique une remise
|
/**
|
||||||
*
|
* Supprime une ligne
|
||||||
*/
|
*/
|
||||||
function set_remise($user, $remise)
|
function deleteline($rowid)
|
||||||
{
|
{
|
||||||
if ($user->rights->facture->creer)
|
if ($this->brouillon)
|
||||||
{
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = $rowid;";
|
||||||
|
$result = $this->db->query( $sql);
|
||||||
|
|
||||||
$this->remise_percent = $remise ;
|
$this->updateprice($this->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET remise_percent = ".ereg_replace(",",".",$remise);
|
/**
|
||||||
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
* Mise à jour des sommes de la facture
|
||||||
|
*/
|
||||||
|
function updateprice($facid)
|
||||||
|
{
|
||||||
|
include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
|
||||||
|
$err=0;
|
||||||
|
$sql = "SELECT price, qty, tva_taux FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = $facid;";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
$result = $this->db->query($sql);
|
||||||
{
|
|
||||||
$this->updateprice($this->id);
|
if ($result)
|
||||||
return 1;
|
{
|
||||||
}
|
$num = $this->db->num_rows();
|
||||||
else
|
$i = 0;
|
||||||
{
|
while ($i < $num)
|
||||||
print $this->db->error() . ' in ' . $sql;
|
{
|
||||||
return 0;
|
$obj = $this->db->fetch_object($result);
|
||||||
}
|
|
||||||
}
|
$products[$i][0] = $obj->price;
|
||||||
}
|
$products[$i][1] = $obj->qty;
|
||||||
|
$products[$i][2] = $obj->tva_taux;
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->free();
|
||||||
|
|
||||||
|
$calculs = calcul_price($products, $this->remise_percent);
|
||||||
|
|
||||||
|
$this->total_remise = $calculs[3];
|
||||||
|
$this->amount_ht = $calculs[4];
|
||||||
|
$this->total_ht = $calculs[0];
|
||||||
|
$this->total_tva = $calculs[1];
|
||||||
|
$this->total_ttc = $calculs[2];
|
||||||
|
$tvas = $calculs[5];
|
||||||
|
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec SET amount = $this->amount_ht, remise=$this->total_remise, total=$this->total_ht, tva=$this->total_tva, total_ttc=$this->total_ttc";
|
||||||
|
$sql .= " WHERE rowid = $facid ;";
|
||||||
|
|
||||||
|
if ( $this->db->query($sql) )
|
||||||
|
{
|
||||||
|
if ($err == 0)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "$sql<br>";
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "Error";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applique une remise
|
||||||
|
*/
|
||||||
|
function set_remise($user, $remise)
|
||||||
|
{
|
||||||
|
if ($user->rights->facture->creer)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->remise_percent = $remise ;
|
||||||
|
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET remise_percent = ".ereg_replace(",",".",$remise);
|
||||||
|
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
||||||
|
|
||||||
|
if ($this->db->query($sql) )
|
||||||
|
{
|
||||||
|
$this->updateprice($this->id);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print $this->db->error() . ' in ' . $sql;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -19,247 +19,232 @@
|
|||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
* $Source$
|
* $Source$
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/compta/facture.php
|
\file htdocs/compta/facture.php
|
||||||
\ingroup facture
|
\ingroup facture
|
||||||
\brief Page de création d'une facture
|
\brief Page de création d'une facture
|
||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require("./pre.inc.php");
|
||||||
|
require_once DOL_DOCUMENT_ROOT."/facture.class.php";
|
||||||
|
require_once DOL_DOCUMENT_ROOT."/paiement.class.php";
|
||||||
|
|
||||||
$user->getrights('facture');
|
$user->getrights('facture');
|
||||||
$user->getrights('banque');
|
$user->getrights('banque');
|
||||||
|
|
||||||
if (!$user->rights->facture->lire)
|
if (!$user->rights->facture->lire)
|
||||||
accessforbidden();
|
accessforbidden();
|
||||||
|
|
||||||
$langs->load("main"); // BUG De chargement de traduction ne pas modifier cette ligne
|
$langs->load("main"); // BUG De chargement de traduction ne pas modifier cette ligne
|
||||||
$langs->load("bills");
|
$langs->load("bills");
|
||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT."/facture.class.php";
|
$warning_delay=31*24*60*60; // Delai affichage warning retard (si retard paiement facture > delai)
|
||||||
require_once DOL_DOCUMENT_ROOT."/paiement.class.php";
|
|
||||||
|
|
||||||
|
|
||||||
if ($_GET["socidp"]) { $socidp=$_GET["socidp"]; }
|
if ($_GET["socidp"]) { $socidp=$_GET["socidp"]; }
|
||||||
/*
|
|
||||||
* Sécurité accés client
|
// Sécurité accés client
|
||||||
*/
|
|
||||||
if ($user->societe_id > 0)
|
if ($user->societe_id > 0)
|
||||||
{
|
{
|
||||||
$action = '';
|
$action = '';
|
||||||
$socidp = $user->societe_id;
|
$socidp = $user->societe_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
llxHeader('','Factures impayées');
|
|
||||||
|
llxHeader('',$langs->trans("UnpayedBills"));
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* *
|
* *
|
||||||
* Mode Liste *
|
* Mode Liste *
|
||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
$page = $_GET["page"];
|
$page = $_GET["page"];
|
||||||
$sortorder=$_GET["sortorder"];
|
|
||||||
$sortfield=$_GET["sortfield"];
|
$sortfield=$_GET["sortfield"];
|
||||||
if (! $sortorder) $sortorder="DESC";
|
$sortorder=$_GET["sortorder"];
|
||||||
if (! $sortfield) $sortfield="f.datef";
|
if (! $sortfield) $sortfield="f.datef";
|
||||||
|
if (! $sortorder) $sortorder="ASC";
|
||||||
if ($page == -1)
|
if ($page == -1) $page = 0;
|
||||||
{
|
|
||||||
$page = 0 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($user->rights->facture->lire)
|
if ($user->rights->facture->lire)
|
||||||
{
|
{
|
||||||
$limit = $conf->liste_limit;
|
$limit = $conf->liste_limit;
|
||||||
$offset = $limit * $page ;
|
$offset = $limit * $page ;
|
||||||
|
|
||||||
|
$sql = "SELECT s.nom,s.idp,f.facnumber,f.increment,f.total,f.total_ttc,";
|
||||||
|
$sql.= $db->pdate("f.datef")." as df, ".$db->pdate("f.date_lim_reglement")." as datelimite, ";
|
||||||
|
$sql.= " f.paye as paye, f.rowid as facid, f.fk_statut, sum(pf.amount) as am";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||||
|
$sql.= ",".MAIN_DB_PREFIX."facture as f";
|
||||||
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture ";
|
||||||
|
$sql.= " WHERE f.fk_soc = s.idp";
|
||||||
|
$sql.= " AND f.paye = 0 AND f.fk_statut = 1";
|
||||||
|
if ($socidp) $sql .= " AND s.idp = $socidp";
|
||||||
|
|
||||||
$sql = "SELECT s.nom,s.idp,f.facnumber,f.increment,f.total,f.total_ttc,".$db->pdate("f.datef")." as df, f.paye as paye, f.rowid as facid, f.fk_statut, sum(pf.amount) as am";
|
if ($_GET["filtre"])
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
|
||||||
$sql .= ",".MAIN_DB_PREFIX."facture as f";
|
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture ";
|
|
||||||
$sql .= " WHERE f.fk_soc = s.idp";
|
|
||||||
$sql .= " AND f.paye = 0 AND f.fk_statut = 1";
|
|
||||||
|
|
||||||
if ($socidp)
|
|
||||||
$sql .= " AND s.idp = $socidp";
|
|
||||||
|
|
||||||
if ($_GET["filtre"])
|
|
||||||
{
|
{
|
||||||
$filtrearr = split(",", $_GET["filtre"]);
|
$filtrearr = split(",", $_GET["filtre"]);
|
||||||
foreach ($filtrearr as $fil)
|
foreach ($filtrearr as $fil)
|
||||||
{
|
{
|
||||||
$filt = split(":", $fil);
|
$filt = split(":", $fil);
|
||||||
$sql .= " AND " . $filt[0] . " = " . $filt[1];
|
$sql .= " AND " . $filt[0] . " = " . $filt[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET["search_ref"])
|
if ($_GET["search_ref"])
|
||||||
{
|
{
|
||||||
$sql .= " AND f.facnumber like '%".$_GET["search_ref"]."%'";
|
$sql .= " AND f.facnumber like '%".$_GET["search_ref"]."%'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET["search_societe"])
|
if ($_GET["search_societe"])
|
||||||
{
|
{
|
||||||
$sql .= " AND s.nom like '%".$_GET["search_societe"]."%'";
|
$sql .= " AND s.nom like '%".$_GET["search_societe"]."%'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET["search_montant_ht"])
|
if ($_GET["search_montant_ht"])
|
||||||
{
|
{
|
||||||
$sql .= " AND f.total = '".$_GET["search_montant_ht"]."'";
|
$sql .= " AND f.total = '".$_GET["search_montant_ht"]."'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET["search_montant_ttc"])
|
if ($_GET["search_montant_ttc"])
|
||||||
{
|
{
|
||||||
$sql .= " AND f.total_ttc = '".$_GET["search_montant_ttc"]."'";
|
$sql .= " AND f.total_ttc = '".$_GET["search_montant_ttc"]."'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($_POST["sf_ref"]) > 0)
|
if (strlen($_POST["sf_ref"]) > 0)
|
||||||
{
|
{
|
||||||
$sql .= " AND f.facnumber like '%".$_POST["sf_ref"] . "%'";
|
$sql .= " AND f.facnumber like '%".$_POST["sf_ref"] . "%'";
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= " GROUP BY f.facnumber";
|
$sql .= " GROUP BY f.facnumber";
|
||||||
|
|
||||||
$sql .= " ORDER BY ";
|
$sql .= " ORDER BY ";
|
||||||
|
$listfield=split(',',$sortfield);
|
||||||
|
foreach ($listfield as $key => $value) $sql.=$listfield[$key]." ".$sortorder.",";
|
||||||
|
$sql .= " f.fk_soc ASC";
|
||||||
|
|
||||||
|
//$sql .= $db->plimit($limit+1,$offset);
|
||||||
|
|
||||||
$listfield=split(',',$sortfield);
|
$result = $db->query($sql);
|
||||||
foreach ($listfield as $key => $value)
|
|
||||||
|
if ($result)
|
||||||
{
|
{
|
||||||
$sql.=$listfield[$key]." ".$sortorder.",";
|
$num = $db->num_rows($result);
|
||||||
|
|
||||||
|
if ($socidp)
|
||||||
|
{
|
||||||
|
$soc = new Societe($db);
|
||||||
|
$soc->fetch($socidp);
|
||||||
|
}
|
||||||
|
|
||||||
|
print_barre_liste($langs->trans("BillsCustomersUnpayed")." ".($socidp?" $soc->nom":""),$page,"impayees.php","&socidp=$socidp",$sortfield,$sortorder,'',$num);
|
||||||
|
$i = 0;
|
||||||
|
print '<table class="liste" width="100%">';
|
||||||
|
print '<tr class="liste_titre">';
|
||||||
|
print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"f.facnumber","","&socidp=$socidp","",$sortfield);
|
||||||
|
print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"f.datef","","&socidp=$socidp",'align="center"',$sortfield);
|
||||||
|
print_liste_field_titre($langs->trans("DateDue"),$_SERVER["PHP_SELF"],"f.date_lim_reglement","","&socidp=$socidp",'align="center"',$sortfield);
|
||||||
|
print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&socidp=$socidp","",$sortfield);
|
||||||
|
print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total","","&socidp=$socidp",'align="right"',$sortfield);
|
||||||
|
print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"f.total_ttc","","&socidp=$socidp",'align="right"',$sortfield);
|
||||||
|
print_liste_field_titre($langs->trans("Received"),$_SERVER["PHP_SELF"],"am","","&socidp=$socidp",'align="right"',$sortfield);
|
||||||
|
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"fk_statut,paye","","&socidp=$socidp",'align="right"',$sortfield);
|
||||||
|
print "</tr>\n";
|
||||||
|
|
||||||
|
// Lignes des champs de filtre
|
||||||
|
print '<form method="get" action="impayees.php">';
|
||||||
|
print '<tr class="liste_titre">';
|
||||||
|
print '<td class="liste_titre" valign="right">';
|
||||||
|
print '<input class="flat" size="10" type="text" name="search_ref" value="'.$_GET["search_ref"].'"></td>';
|
||||||
|
print '<td class="liste_titre"> </td>';
|
||||||
|
print '<td class="liste_titre"> </td>';
|
||||||
|
print '<td class="liste_titre" align="left">';
|
||||||
|
print '<input class="flat" type="text" name="search_societe" value="'.$_GET["search_societe"].'">';
|
||||||
|
print '</td><td class="liste_titre" align="right">';
|
||||||
|
print '<input class="flat" type="text" size="10" name="search_montant_ht" value="'.$_GET["search_montant_ht"].'">';
|
||||||
|
print '</td><td class="liste_titre" align="right">';
|
||||||
|
print '<input class="flat" type="text" size="10" name="search_montant_ttc" value="'.$_GET["search_montant_ttc"].'">';
|
||||||
|
print '</td><td class="liste_titre" colspan="2" align="right">';
|
||||||
|
print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans("Search").'">';
|
||||||
|
print '</td>';
|
||||||
|
print "</tr>\n";
|
||||||
|
print '</form>';
|
||||||
|
|
||||||
|
if ($num > 0)
|
||||||
|
{
|
||||||
|
$var=True;
|
||||||
|
$total=0;
|
||||||
|
$totalrecu=0;
|
||||||
|
|
||||||
|
while ($i < $num)
|
||||||
|
{
|
||||||
|
$objp = $db->fetch_object($result);
|
||||||
|
|
||||||
|
$var=!$var;
|
||||||
|
|
||||||
|
print "<tr $bc[$var]>";
|
||||||
|
$class = "impayee";
|
||||||
|
|
||||||
|
print '<td nowrap><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill")."</a> ";
|
||||||
|
print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$objp->facid.'">'.$objp->facnumber.'</a>'.$objp->increment;
|
||||||
|
if ($objp->datelimite < (time() - $warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am) print img_warning($langs->trans("Late"));
|
||||||
|
print "</td>\n";
|
||||||
|
|
||||||
|
print "<td nowrap align=\"center\">".dolibarr_print_date($objp->df)."</td>\n";
|
||||||
|
print "<td nowrap align=\"center\">".dolibarr_print_date($objp->datelimite)."</td>\n";
|
||||||
|
|
||||||
|
print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$objp->nom.'</a></td>';
|
||||||
|
|
||||||
|
print "<td align=\"right\">".price($objp->total)."</td>";
|
||||||
|
print "<td align=\"right\">".price($objp->total_ttc)."</td>";
|
||||||
|
print "<td align=\"right\">".price($objp->am)."</td>";
|
||||||
|
|
||||||
|
// Affiche statut de la facture
|
||||||
|
if (! $objp->paye)
|
||||||
|
{
|
||||||
|
if ($objp->fk_statut == 0)
|
||||||
|
{
|
||||||
|
print '<td align="center">'.$langs->trans("BillShortStatusDraft").'</td>';
|
||||||
|
}
|
||||||
|
elseif ($objp->fk_statut == 3)
|
||||||
|
{
|
||||||
|
print '<td align="center">'.$langs->trans("BillShortStatusCanceled").'</td>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print '<td align="center"><a class="'.$class.'" href="'.$_SERVER["PHP_SELF"].'?filtre=paye:0,fk_statut:1">'.($objp->am?$langs->trans("BillShortStatusStarted"):$langs->trans("BillShortStatusNotPayed")).'</a></td>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print '<td align="center">'.$langs->trans("BillShortStatusPayed").'</td>';
|
||||||
|
}
|
||||||
|
|
||||||
|
print "</tr>\n";
|
||||||
|
$total+=$objp->total;
|
||||||
|
$total_ttc+=$objp->total_ttc;
|
||||||
|
$totalrecu+=$objp->am;
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
print '<tr class="liste_total">';
|
||||||
|
print "<td colspan=3 align=\"left\">".$langs->trans("Total").": </td>";
|
||||||
|
print "<td align=\"right\"><b>".price($total)."</b></td>";
|
||||||
|
print "<td align=\"right\"><b>".price($total_ttc)."</b></td>";
|
||||||
|
print "<td align=\"right\"><b>".price($totalrecu)."</b></td>";
|
||||||
|
print '<td align="center"> </td>';
|
||||||
|
print "</tr>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
print "</table>";
|
||||||
|
$db->free();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
$sql .= " f.fk_soc DESC "; // Grouper les lignes pas sociétés
|
|
||||||
|
|
||||||
//$sql .= $db->plimit($limit+1,$offset);
|
|
||||||
|
|
||||||
$result = $db->query($sql);
|
|
||||||
|
|
||||||
if ($result)
|
|
||||||
{
|
{
|
||||||
$num = $db->num_rows();
|
dolibarr_print_error($db);
|
||||||
|
|
||||||
if ($socidp)
|
|
||||||
{
|
|
||||||
$soc = new Societe($db);
|
|
||||||
$soc->fetch($socidp);
|
|
||||||
}
|
|
||||||
|
|
||||||
print_barre_liste($langs->trans("BillsCustomersUnpayed")." ".($socidp?" $soc->nom":""),$page,"impayees.php","&socidp=$socidp",$sortfield,$sortorder,'',$num);
|
|
||||||
$i = 0;
|
|
||||||
print '<table class="liste" width="100%">';
|
|
||||||
print '<tr class="liste_titre">';
|
|
||||||
print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"f.facnumber","","&socidp=$socidp","",$sortfield);
|
|
||||||
print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"f.datef","","&socidp=$socidp",'align="center"',$sortfield);
|
|
||||||
print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&socidp=$socidp","",$sortfield);
|
|
||||||
print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total","","&socidp=$socidp",'align="right"',$sortfield);
|
|
||||||
print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"f.total_ttc","","&socidp=$socidp",'align="right"',$sortfield);
|
|
||||||
print_liste_field_titre($langs->trans("Received"),$_SERVER["PHP_SELF"],"am","","&socidp=$socidp",'align="right"',$sortfield);
|
|
||||||
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"fk_statut,paye","","&socidp=$socidp",'align="right"',$sortfield);
|
|
||||||
print "</tr>\n";
|
|
||||||
|
|
||||||
// Lignes des champs de filtre
|
|
||||||
print '<form method="get" action="impayees.php">';
|
|
||||||
print '<tr class="liste_titre">';
|
|
||||||
print '<td class="liste_titre" valign="right">';
|
|
||||||
print '<input class="flat" size="10" type="text" name="search_ref" value="'.$_GET["search_ref"].'">';
|
|
||||||
print '</td><td class="liste_titre"> </td>';
|
|
||||||
print '<td class="liste_titre" align="left">';
|
|
||||||
print '<input class="flat" type="text" name="search_societe" value="'.$_GET["search_societe"].'">';
|
|
||||||
print '</td><td class="liste_titre" align="right">';
|
|
||||||
print '<input class="flat" type="text" size="10" name="search_montant_ht" value="'.$_GET["search_montant_ht"].'">';
|
|
||||||
print '</td><td class="liste_titre" align="right">';
|
|
||||||
print '<input class="flat" type="text" size="10" name="search_montant_ttc" value="'.$_GET["search_montant_ttc"].'">';
|
|
||||||
print '</td><td class="liste_titre" colspan="2" align="right">';
|
|
||||||
print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans("Search").'">';
|
|
||||||
print '</td>';
|
|
||||||
print "</tr>\n";
|
|
||||||
print '</form>';
|
|
||||||
|
|
||||||
if ($num > 0)
|
|
||||||
{
|
|
||||||
$var=True;
|
|
||||||
$total=0;
|
|
||||||
$totalrecu=0;
|
|
||||||
|
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$objp = $db->fetch_object($result);
|
|
||||||
|
|
||||||
if ($objp->am == 0)
|
|
||||||
{
|
|
||||||
$var=!$var;
|
|
||||||
|
|
||||||
print "<tr $bc[$var]>";
|
|
||||||
$class = "impayee";
|
|
||||||
|
|
||||||
print '<td><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill")."</a> ";
|
|
||||||
print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$objp->facid.'">'.$objp->facnumber.'</a>'.$objp->increment."</td>\n";
|
|
||||||
|
|
||||||
if ($objp->df > 0 )
|
|
||||||
{
|
|
||||||
print "<td align=\"center\">";
|
|
||||||
print strftime("%d %b %Y",$objp->df)."</td>\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "<td align=\"center\"><b>!!!</b></td>\n";
|
|
||||||
}
|
|
||||||
print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$objp->nom.'</a></td>';
|
|
||||||
|
|
||||||
print "<td align=\"right\">".price($objp->total)."</td>";
|
|
||||||
print "<td align=\"right\">".price($objp->total_ttc)."</td>";
|
|
||||||
print "<td align=\"right\">".price($objp->am)."</td>";
|
|
||||||
|
|
||||||
// Affiche statut de la facture
|
|
||||||
if (! $objp->paye)
|
|
||||||
{
|
|
||||||
if ($objp->fk_statut == 0)
|
|
||||||
{
|
|
||||||
print '<td align="center">'.$langs->trans("BillShortStatusDraft").'</td>';
|
|
||||||
}
|
|
||||||
elseif ($objp->fk_statut == 3)
|
|
||||||
{
|
|
||||||
print '<td align="center">'.$langs->trans("BillShortStatusCanceled").'</td>';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print '<td align="center"><a class="'.$class.'" href="'.$_SERVER["PHP_SELF"].'?filtre=paye:0,fk_statut:1">'.($objp->am?$langs->trans("BillShortStatusStarted"):$langs->trans("BillShortStatusNotPayed")).'</a></td>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print '<td align="center">'.$langs->trans("BillShortStatusPayed").'</td>';
|
|
||||||
}
|
|
||||||
|
|
||||||
print "</tr>\n";
|
|
||||||
$total+=$objp->total;
|
|
||||||
$total_ttc+=$objp->total_ttc;
|
|
||||||
$totalrecu+=$objp->am;
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
print '<tr class="liste_total">';
|
|
||||||
print "<td colspan=3 align=\"left\">".$langs->trans("Total").": </td>";
|
|
||||||
print "<td align=\"right\"><b>".price($total)."</b></td>";
|
|
||||||
print "<td align=\"right\"><b>".price($total_ttc)."</b></td>";
|
|
||||||
print "<td align=\"right\"><b>".price($totalrecu)."</b></td>";
|
|
||||||
print '<td align="center"> </td>';
|
|
||||||
print "</tr>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
print "</table>";
|
|
||||||
$db->free();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_print_error($db);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,9 @@
|
|||||||
|
|
||||||
require("./pre.inc.php");
|
require("./pre.inc.php");
|
||||||
|
|
||||||
|
$langs->load("bills");
|
||||||
|
|
||||||
|
|
||||||
// Sécurité accés client
|
// Sécurité accés client
|
||||||
if ($user->societe_id > 0)
|
if ($user->societe_id > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -30,6 +30,8 @@
|
|||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\class Facture
|
\class Facture
|
||||||
|
|||||||
@ -27,11 +27,12 @@
|
|||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
|
||||||
|
|
||||||
|
|
||||||
/** \class Ficheinter
|
/** \class Ficheinter
|
||||||
\brief Classe des gestion des fiches interventions
|
\brief Classe des gestion des fiches interventions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Fichinter
|
class Fichinter
|
||||||
{
|
{
|
||||||
var $id;
|
var $id;
|
||||||
@ -237,7 +238,6 @@ class Fichinter
|
|||||||
*/
|
*/
|
||||||
$mesg = "La fiche d'intervention ".$this->ref." a été validée.\n";
|
$mesg = "La fiche d'intervention ".$this->ref." a été validée.\n";
|
||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
|
|
||||||
$notify = New Notify($this->db);
|
$notify = New Notify($this->db);
|
||||||
$notify->send($action_notify, $this->societe_id, $mesg, "ficheinter", $this->id, $filepdf);
|
$notify->send($action_notify, $this->societe_id, $mesg, "ficheinter", $this->id, $filepdf);
|
||||||
|
|
||||||
|
|||||||
@ -102,11 +102,10 @@ define('MAIN_DB_PREFIX','llx_'); // A terme cette constan
|
|||||||
* Chargement des includes principaux
|
* Chargement des includes principaux
|
||||||
*/
|
*/
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/lib/".$conf->db->type.".lib.php");
|
require_once(DOL_DOCUMENT_ROOT ."/lib/".$conf->db->type.".lib.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/user.class.php");
|
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php");
|
require_once(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php");
|
require_once(DOL_DOCUMENT_ROOT ."/user.class.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/menu.class.php");
|
require_once(DOL_DOCUMENT_ROOT ."/menu.class.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/address.class.php");
|
require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php");
|
||||||
|
|
||||||
|
|
||||||
$db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name);
|
$db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user