diff --git a/htdocs/cashdesk/affIndex.php b/htdocs/cashdesk/affIndex.php
index 802e90cdbf9..00c1bd9f338 100644
--- a/htdocs/cashdesk/affIndex.php
+++ b/htdocs/cashdesk/affIndex.php
@@ -46,8 +46,8 @@ print ''."\n";
print ''."\n";
-print ''."\n";
-print ''."\n";
+print ''."\n";
+print ''."\n";
print ''."\n";
print '
'."\n";
diff --git a/htdocs/cashdesk/classes/Mysql.class.php b/htdocs/cashdesk/classes/Mysql.class.php
index eb07c167e58..75b2e23f3d1 100644
--- a/htdocs/cashdesk/classes/Mysql.class.php
+++ b/htdocs/cashdesk/classes/Mysql.class.php
@@ -1,7 +1,7 @@
* Copyright (C) 2008 Laurent Destailleur
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -30,7 +30,7 @@ class Sql implements intSql {
* @param $aBase Nom de la base de donn�es � utiliser
*/
public function __construct ($aHost, $aUser, $aPass, $aBase) {
-
+
$db = mysql_connect ($aHost, $aUser, $aPass);
mysql_select_db ($aBase, $db);
@@ -47,8 +47,8 @@ class Sql implements intSql {
// }
/**
- * Effectue une requ�te sur la base de donn�es, et renvoi la ressource correspondante
- * @param $aRequete Requ�te SQL (ex : SELECT nom, prenom FROM table1 WHERE id = 127)
+ * Effectue une requete sur la base de donn�es, et renvoi la ressource correspondante
+ * @param $aRequete Requete SQL (ex : SELECT nom, prenom FROM table1 WHERE id = 127)
* @return Ressource vers la requ�te venant d'�tre effectu�e
*/
public function query ($aRequete) {
diff --git a/htdocs/cashdesk/facturation.php b/htdocs/cashdesk/facturation.php
index 97879ea9535..59f598b9db9 100644
--- a/htdocs/cashdesk/facturation.php
+++ b/htdocs/cashdesk/facturation.php
@@ -17,41 +17,52 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-// Recuperation de la liste des articles
+// Get list of articles (in warehouse '$conf_fkentrepot' if stock module enabled)
if ( $_GET['filtre'] ) {
// Avec filtre
$ret=array(); $i=0;
- $resql=$sql->query (
- 'SELECT '.MAIN_DB_PREFIX.'product.rowid, ref, label, tva_tx
- FROM '.MAIN_DB_PREFIX.'product
- LEFT JOIN '.MAIN_DB_PREFIX.'product_stock ON '.MAIN_DB_PREFIX.'product.rowid = '.MAIN_DB_PREFIX.'product_stock.fk_product
- WHERE envente = 1
- AND fk_product_type = 0
- AND fk_entrepot = '.$conf_fkentrepot.'
- AND ref LIKE \'%'.$_GET['filtre'].'%\'
- OR label LIKE \'%'.$_GET['filtre'].'%\'
- ORDER BY label');
- while ( $tab = $sql->fetch_array($resql) )
+
+ $request="SELECT p.rowid, p.ref, p.label, p.tva_tx
+ FROM ".MAIN_DB_PREFIX."product as p
+ LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product
+ WHERE p.envente = 1
+ AND p.fk_product_type = 0";
+ if ($conf->stock->enabled) $request.=" AND ps.fk_entrepot = '".$conf_fkentrepot."'";
+ $request.=" AND (p.ref LIKE '%".$_GET['filtre']."%'
+ OR p.label LIKE '%".$_GET['filtre']."%')
+ ORDER BY label";
+ dol_syslog($request);
+ $resql=$sql->query ($request);
+ if ($resql)
{
- foreach ( $tab as $cle => $valeur )
+ while ( $tab = $sql->fetch_array($resql) )
{
- $ret[$i][$cle] = $valeur;
+ foreach ( $tab as $cle => $valeur )
+ {
+ $ret[$i][$cle] = $valeur;
+ }
+ $i++;
}
- $i++;
+ }
+ else
+ {
+ dol_print_error($db);
}
$tab_designations=$ret;
} else {
// Sans filtre
$ret=array(); $i=0;
- $resql=$sql->query ('SELECT '.MAIN_DB_PREFIX.'product.rowid, ref, label, tva_tx
+ $request='SELECT '.MAIN_DB_PREFIX.'product.rowid, ref, label, tva_tx
FROM '.MAIN_DB_PREFIX.'product
LEFT JOIN '.MAIN_DB_PREFIX.'product_stock ON '.MAIN_DB_PREFIX.'product.rowid = '.MAIN_DB_PREFIX.'product_stock.fk_product
WHERE envente = 1
AND fk_product_type = 0
AND fk_entrepot = '.$conf_fkentrepot.'
- ORDER BY label');
+ ORDER BY label';
+ dol_syslog($request);
+ $resql=$sql->query ($request);
while ( $tab = $sql->fetch_array($resql) )
{
foreach ( $tab as $cle => $valeur )
diff --git a/htdocs/cashdesk/facturation_dhtml.php b/htdocs/cashdesk/facturation_dhtml.php
index b791f7bf1c4..7c63b79fdd8 100644
--- a/htdocs/cashdesk/facturation_dhtml.php
+++ b/htdocs/cashdesk/facturation_dhtml.php
@@ -17,24 +17,29 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+/**
+ * This page is called each time we press a key in the code or description
+ * search form to show product combo list
+ */
include('../master.inc.php');
require ('include/environnement.php');
$langs->load("@cashdesk");
// Verification
-if ( strlen ($_GET["code"]) > 1 ) {
-
- $res = $sql->query (
- "SELECT ".MAIN_DB_PREFIX."product.rowid, ref, label, tva_tx
- FROM ".MAIN_DB_PREFIX."product
- LEFT JOIN ".MAIN_DB_PREFIX."product_stock ON ".MAIN_DB_PREFIX."product.rowid = ".MAIN_DB_PREFIX."product_stock.fk_product
- WHERE envente = 1
- AND fk_product_type = 0
- AND fk_entrepot = '".$conf_fkentrepot."'
- AND ref LIKE '%".$_GET['code']."%'
- OR label LIKE '%".$_GET['code']."%'
- ORDER BY label");
+if ( strlen ($_GET["code"]) >= 0 ) // If at least one key
+{
+ $request="SELECT p.rowid, p.ref, p.label, p.tva_tx
+ FROM ".MAIN_DB_PREFIX."product as p
+ LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product
+ WHERE p.envente = 1
+ AND p.fk_product_type = 0";
+ if ($conf->stock->enabled) $request.=" AND ps.fk_entrepot = '".$conf_fkentrepot."'";
+ $request.=" AND (p.ref LIKE '%".$_GET['code']."%'
+ OR p.label LIKE '%".$_GET['code']."%')
+ ORDER BY label";
+ dol_syslog($request);
+ $res = $sql->query ($request);
if ( $nbr = $sql->num_rows($res) ) {
diff --git a/htdocs/cashdesk/include/environnement.php b/htdocs/cashdesk/include/environnement.php
index 98286639e45..2792620203b 100644
--- a/htdocs/cashdesk/include/environnement.php
+++ b/htdocs/cashdesk/include/environnement.php
@@ -52,10 +52,10 @@ if ($conf->stock->enabled && empty($conf_fkentrepot)) dol_print_error("Setup of
$conf_taille_listes = 200; // Nombre max de lignes a afficher dans les listes
$conf_nbr_car_listes = 60; // Nombre max de caracteres par ligne dans les listes
-$new_conf_db_type=$conf_db_type;
-if (eregi('mysql',$new_conf_db_type)) $new_conf_db_type='Mysql';
-
-require ('classes/'.$new_conf_db_type.'.class.php');
+//$new_conf_db_type=$conf_db_type;
+//if (eregi('mysql',$new_conf_db_type)) $new_conf_db_type='Mysql';
+//require ('classes/'.$new_conf_db_type.'.class.php');
//$sql = new Sql ($conf_db_host, $conf_db_user, $conf_db_pass, $conf_db_base);
+
$sql=$db;
?>
diff --git a/htdocs/cashdesk/javascript/dhtml.js b/htdocs/cashdesk/javascript/dhtml.js
index 3bba620636c..b40f84f8e40 100644
--- a/htdocs/cashdesk/javascript/dhtml.js
+++ b/htdocs/cashdesk/javascript/dhtml.js
@@ -61,7 +61,6 @@ function afficheDonnees (aId, aTexte) {
// aCible : id du bloc de destination; aCode : argument à passer à la page php chargée du traitement et de l'affichage
function verifResultat (aCible, aCode) {
-
if (aCode != '') {
if (texte = file ('facturation_dhtml.php?code='+escape(aCode))) {
diff --git a/htdocs/cashdesk/templates/liste_articles.tpl.php b/htdocs/cashdesk/templates/liste_articles.tpl.php
index 7734b171154..d0f8bba8f3f 100644
--- a/htdocs/cashdesk/templates/liste_articles.tpl.php
+++ b/htdocs/cashdesk/templates/liste_articles.tpl.php
@@ -26,10 +26,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
query ('SELECT id, ref, label, qte, price, remise_percent, remise, total_ht, total_ttc FROM '.MAIN_DB_PREFIX.'tmp_caisse as c
+ $request='SELECT id, ref, label, qte, price, remise_percent, remise, total_ht, total_ttc FROM '.MAIN_DB_PREFIX.'tmp_caisse as c
LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON c.fk_article = p.rowid
- ORDER BY id');
-
+ ORDER BY id';
+ dol_syslog($request);
+ $res = $sql->query ($request);
if ( $sql->num_rows($res) ) {
$ret=array(); $i=0;
diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php
index 47fe66c7f24..02d868a3cfa 100644
--- a/htdocs/cashdesk/validation_verif.php
+++ b/htdocs/cashdesk/validation_verif.php
@@ -48,32 +48,24 @@ switch ( $_GET['action'] )
$obj_facturation->mode_reglement ($_POST['hdnChoix']);
- // Si paiement autre qu'en esp�ces, montant encaiss� = prix total
+ // Si paiement autre qu'en especes, montant encaisse = prix total
$mode_reglement = $obj_facturation->mode_reglement();
if ( $mode_reglement != 'ESP' ) {
-
$montant = $obj_facturation->prix_total_ttc();
-
} else {
-
$montant = $_POST['txtEncaisse'];
-
}
if ( $mode_reglement != 'DIF') {
-
$obj_facturation->montant_encaisse ($montant);
- //D�termination de la somme rendue
+ //Determination de la somme rendue
$total = $obj_facturation->prix_total_ttc ();
$encaisse = $obj_facturation->montant_encaisse();
$obj_facturation->montant_rendu ( $encaisse - $total );
-
} else {
-
$obj_facturation->paiement_le ($_POST['txtDatePaiement']);
-
}
$redirection = 'affIndex.php?menu=validation';
@@ -92,339 +84,53 @@ switch ( $_GET['action'] )
$date = date ('Y-m-d');
$heure = date ('H:i:s');
- // Recuperation du mode de reglement et cr�ation de la note privee ...
$note = '';
- switch ( $obj_facturation->mode_reglement() ) {
-
+ switch ( $obj_facturation->mode_reglement() )
+ {
+ case 'DIF':
+ $mode_reglement_id = 0;
+ //$cond_reglement_id = dol_getIdFromCode($db,'RECEP','cond_reglement','code','rowid')
+ $cond_reglement_id = 0;
+ break;
case 'ESP':
- $mode_reglement = 4;
-
- $note .= 'Reglement en especes'."\n";
- $note .= 'Somme encaissee : '.$obj_facturation->montant_encaisse()." euro\n";
- $note .= 'Somme rendue : '.$obj_facturation->montant_rendu()." euro\n";
+ $mode_reglement_id = dol_getIdFromCode($db,$obj_facturation->mode_reglement(),'c_paiement');
+ $cond_reglement_id = 0;
+ $note .= $langs->trans("Cash")."\n";
+ $note .= $langs->trans("Received").' : '.$obj_facturation->montant_encaisse()." ".$conf->monnaie."\n";
+ $note .= $langs->trans("Rendu").' : '.$obj_facturation->montant_rendu()." ".$conf->monnaie."\n";
$note .= "\n";
$note .= '--------------------------------------'."\n\n";
break;
-
case 'CB':
- $mode_reglement = 6;
+ $mode_reglement_id = dol_getIdFromCode($db,$obj_facturation->mode_reglement(),'c_paiement');
+ $cond_reglement_id = 0;
break;
-
case 'CHQ':
- $mode_reglement = 7;
+ $mode_reglement_id = dol_getIdFromCode($db,$obj_facturation->mode_reglement(),'c_paiement');
+ $cond_reglement_id = 0;
break;
-
}
// ... on termine la note
- $note .= addslashes ($_POST['txtaNotes']);
-
-
- // TODO Add records into database using the Dolibarr business classes
- // instead of direct access.
- // Also add a transaction and error management
-
-
- // Si paiement differe ...
- if ( $obj_facturation->mode_reglement() == 'DIF' )
- {
-
- // ... ajout d'une facture sans mode de reglement, avec la date d'�ch�ance
- $sql->query (
- "INSERT INTO ".MAIN_DB_PREFIX."facture (
- facnumber,
- type,
- ref_client,
- increment,
- fk_soc,
- datec,
- datef,
- date_valid,
- paye,
- amount,
- remise_percent,
- remise_absolue,
- remise,
- close_code,
- close_note,
- tva,
- total,
- total_ttc,
- fk_statut,
- fk_user_author,
- fk_user_valid,
- fk_facture_source,
- fk_projet,
- fk_cond_reglement,
- fk_mode_reglement,
- date_lim_reglement,
- note,
- model_pdf
- ) VALUES (
- '".$obj_facturation->num_facture()."',
- 0,
- NULL,
- NULL,
- ".$conf_fksoc.",
- '".$date." ".$heure."',
- '".$date."',
- NULL,
- 0,
- ".$obj_facturation->prix_total_ht().",
- 0,
- 0,
- 0,
- NULL,
- NULL,
- ".$obj_facturation->montant_tva().",
- ".$obj_facturation->prix_total_ht().",
- ".$obj_facturation->prix_total_ttc().",
- 1,
- ".$_SESSION['uid'].",
- ".$_SESSION['uid'].",
- NULL,
- NULL,
- 0,
- 255,
- '".$obj_facturation->paiement_le()."',
- '".$note."',
- 'crabe'
- );");
-
-
- // Recuperation de l'id de la facture nouvellement creee
- $resql=$sql->query ("SELECT rowid
- FROM ".MAIN_DB_PREFIX."facture
- WHERE 1
- ORDER BY rowid DESC");
-
- $ret=array();
- $tab = $sql->fetch_array($resql);
- foreach ( $tab as $cle => $valeur )
- {
- $ret[$cle] = $valeur;
- }
- $tab_id_facture=$ret;
-
- $id = $tab_id_facture['rowid'];
-
-
- // Sinon ...
- }
- else
- {
-
- // ... ajout d'une facture et d'un paiement
- $sql->query ("INSERT INTO ".MAIN_DB_PREFIX."facture (
- facnumber,
- type,
- ref_client,
- increment,
- fk_soc,
- datec,
- datef,
- date_valid,
- paye,
- amount,
- remise_percent,
- remise_absolue,
- remise,
- close_code,
- close_note,
- tva,
- total,
- total_ttc,
- fk_statut,
- fk_user_author,
- fk_user_valid,
- fk_facture_source,
- fk_projet,
- fk_cond_reglement,
- fk_mode_reglement,
- date_lim_reglement,
- note,
- note_public)
-
- VALUES (
- '".$obj_facturation->num_facture()."',
- 0,
- NULL,
- NULL,
- ".$conf_fksoc.",
- '".$date." ".$heure."',
- '".$date."',
- NULL,
- 1,
- ".$obj_facturation->prix_total_ht().",
- 0,
- 0,
- 0,
- NULL,
- NULL,
- ".$obj_facturation->montant_tva().",
- ".$obj_facturation->prix_total_ht().",
- ".$obj_facturation->prix_total_ttc().",
- 2,
- ".$_SESSION['uid'].",
- ".$_SESSION['uid'].",
- NULL,
- NULL,
- 1,
- ".$mode_reglement.",
- '".$date."',
- '".$note."',
- NULL)
- ");
-
-
- // Recuperation de l'id de la facture nouvellement creee
- $resql=$sql->query (
- "SELECT rowid
- FROM ".MAIN_DB_PREFIX."facture
- WHERE 1
- ORDER BY rowid DESC");
-
- $ret=array();
- $tab = $sql->fetch_array($resql);
- foreach ( $tab as $cle => $valeur )
- {
- $ret[$cle] = $valeur;
- }
-
- $tab_id_facture = $tab;
-
- $id = $tab_id_facture['rowid'];
+ $note .= $_POST['txtaNotes'];
- // Ajout d'une operation sur le compte de caisse, uniquement si le paiement est en especes
- if ( $obj_facturation->mode_reglement() == 'ESP' )
- {
+ $sql->begin();
- $sql->query (
- "INSERT INTO ".MAIN_DB_PREFIX."bank (
- datec,
- datev,
- dateo,
- amount,
- label,
- fk_account,
- fk_user_author,
- fk_type,
- rappro,
- fk_bordereau
- )
+ $user->id=$_SESSION['uid'];
+ $user->fetch();
+ $user->getrights();
- VALUES (
- '".$date." ".$heure."',
- '".$date."',
- '".$date."',
- ".$obj_facturation->prix_total_ttc().",
- 'Paiement caisse facture ".$obj_facturation->num_facture()."',
- ".$conf_fkaccount.",
- ".$_SESSION['uid'].",
- 'ESP',
- 0,
- 0
- )
- ");
-
- }
-
- // Recuperation de l'id de l'operation nouvellement creee
- $resql=$sql->query (
- "SELECT rowid
- FROM ".MAIN_DB_PREFIX."bank
- WHERE 1
- ORDER BY rowid DESC");
-
- $ret=array();
- $tab = $sql->fetch_array($resql);
- foreach ( $tab as $cle => $valeur )
- {
- $ret[$cle] = $valeur;
- }
-
- $tab_id_operation = $tab;
-
- $id_op = $tab_id_operation['rowid'];
-
-
- // Ajout d'un nouveau paiement
- $sql->query (
- "INSERT INTO ".MAIN_DB_PREFIX."paiement (
- fk_facture,
- datec,
- datep,
- amount,
- fk_paiement,
- num_paiement,
- note,
- fk_bank,
- fk_user_creat,
- fk_user_modif,
- statut,
- fk_export_compta
- )
-
- VALUES (
- ".$id.",
- '".$date." ".$heure."',
- '".$date." 12:00:00',
- ".$obj_facturation->prix_total_ttc().",
- ".$mode_reglement.",
- NULL,
- NULL,
- $id_op,
- ".$_SESSION['uid'].",
- NULL,
- 1,
- 0
- )");
-
-
- // Recuperation de l'id du paiement nouvellement cr�
- $resql=$sql->query (
- "SELECT rowid
- FROM ".MAIN_DB_PREFIX."paiement
- WHERE 1
- ORDER BY rowid DESC");
-
- $ret=array();
- $tab = $sql->fetch_array($resql);
- foreach ( $tab as $cle => $valeur )
- {
- $ret[$cle] = $valeur;
- }
-
- $tab_id_paiement = $tab;
-
- $id_paiement = $tab_id_paiement['rowid'];
-
-
- $sql->query (
- "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (
- fk_paiement,
- fk_facture,
- amount
- )
-
- VALUES (
- ".$id_paiement.",
- ".$id.",
- ".$obj_facturation->prix_total_ttc()."
- )
- ");
-
- }
+ $now=dol_now('tzserver');
+ $invoice=new Facture($sql,$conf_fksoc);
// Recuperation de la liste des articles du panier
$res=$sql->query ('
- SELECT fk_article, qte, fk_tva, remise_percent, remise, total_ht, total_ttc, reel
+ SELECT fk_article, qte, fk_tva, remise_percent, remise, total_ht, total_ttc
FROM '.MAIN_DB_PREFIX.'tmp_caisse
- LEFT JOIN '.MAIN_DB_PREFIX.'product_stock ON '.MAIN_DB_PREFIX.'tmp_caisse.fk_article = '.MAIN_DB_PREFIX.'product_stock.fk_product
WHERE 1');
$ret=array(); $i=0;
while ( $tab = $sql->fetch_array($res) )
@@ -435,13 +141,10 @@ switch ( $_GET['action'] )
}
$i++;
}
-
$tab_liste = $ret;
-
// Loop on each product
for ($i = 0; $i < count ($tab_liste); $i++)
{
-
// Recuperation de l'article
$res = $sql->query (
'SELECT label, tva_tx, price
@@ -467,18 +170,26 @@ switch ( $_GET['action'] )
}
$tab_tva = $ret;
+ $invoiceline=new FactureLigne($db);
+ $invoiceline->fk_product=$tab_liste[$i]['fk_article'];
+ $invoiceline->desc=$tab_article['label'];
+ $invoiceline->tva_tx=$tab_tva['taux'];
+ $invoiceline->qty=$tab_liste[$i]['qte'];
+ $invoiceline->remise_percent=$tab_liste[$i]['remise_percent'];
+ $invoiceline->price=$tab_article['price'];
+ $invoiceline->subprice=$tab_article['price'];
+ $invoiceline->total_ht=$tab_liste[$i]['total_ht'];
+ $invoiceline->total_ttc=$tab_liste[$i]['total_ttc'];
+ $invoiceline->total_tva=($tab_liste[$i]['total_ttc']-$tab_liste[$i]['total_ht']);
+ $invoice->lignes[]=$invoiceline;
// Calcul du montant de la TVA
- $montant_tva = $tab_liste[$i]['total_ttc'] - $tab_liste[$i]['total_ht'];
-
+/* $montant_tva = $tab_liste[$i]['total_ttc'] - $tab_liste[$i]['total_ht'];
// Calcul de la position de l'article dans la liste
- $position = $i + 1;
-
-
$reel = $tab_liste[$i]['reel'];
$qte = $tab_liste[$i]['qte'];
$stock = $reel - $qte;
-
+ $position = $i + 1;
// Ajout d'une entree dans le detail de la facture
$sql->query (
@@ -524,19 +235,172 @@ switch ( $_GET['action'] )
0,
0,
".$position.")");
+ */
+ }
+
+
+ // Si paiement differe ...
+ if ( $obj_facturation->mode_reglement() == 'DIF' )
+ {
+ $invoice->socid=$conf_fksoc;
+ $invoice->date_creation=$now;
+ $invoice->date=$now;
+ $invoice->total_ht=$obj_facturation->prix_total_ht();
+ $invoice->total_tva=$obj_facturation->montant_tva();
+ $invoice->total_ttc=$obj_facturation->prix_total_ttc();
+ $invoice->note=$note;
+ $invoice->cond_reglement_id=$cond_reglement_id;
+ $invoice->mode_reglement_id=$mode_reglement_id;
+ //print "c=".$invoice->cond_reglement_id." m=".$invoice->mode_reglement_id; exit;
+ $result=$invoice->create($user,0,dol_stringtotime($obj_facturation->paiement_le()));
+ $result=$invoice->set_valid($user,$conf_fksoc,$obj_facturation->num_facture());
+
+ $id = $invoice->id;
+ }
+ else
+ {
+ $now=dol_now('tzserver');
+ $invoice=new Facture($sql,$conf_fksoc);
+ $invoice->socid=$conf_fksoc;
+ $invoice->date_creation=$now;
+ $invoice->date=$now;
+ $invoice->date_lim_reglement=0;
+ $invoice->total_ht=$obj_facturation->prix_total_ht();
+ $invoice->total_tva=$obj_facturation->montant_tva();
+ $invoice->total_ttc=$obj_facturation->prix_total_ttc();
+ $invoice->note=$note;
+ $invoice->cond_reglement_id=$cond_reglement_id;
+ $invoice->mode_reglement_id=$mode_reglement_id;
+
+ $result=$invoice->create($user,0,0);
+ $result=$invoice->set_valid($user,$conf_fksoc,$obj_facturation->num_facture());
+
+ $id = $invoice->id;
+
+ // Add the payment
+ // TODO Manage ESP, CHQ...
+
+ // Ajout d'une operation sur le compte de caisse, uniquement si le paiement est en especes
+ if ( $obj_facturation->mode_reglement() == 'ESP' )
+ {
+ $sql->query (
+ "INSERT INTO ".MAIN_DB_PREFIX."bank (
+ datec,
+ datev,
+ dateo,
+ amount,
+ label,
+ fk_account,
+ fk_user_author,
+ fk_type,
+ rappro,
+ fk_bordereau
+ )
+
+ VALUES (
+ '".$date." ".$heure."',
+ '".$date."',
+ '".$date."',
+ ".$obj_facturation->prix_total_ttc().",
+ 'Paiement caisse facture ".$obj_facturation->num_facture()."',
+ ".$conf_fkaccount.",
+ ".$_SESSION['uid'].",
+ 'ESP',
+ 0,
+ 0
+ )
+ ");
+
+ }
+ // Recuperation de l'id de l'operation nouvellement creee
+ $resql=$sql->query (
+ "SELECT rowid
+ FROM ".MAIN_DB_PREFIX."bank
+ WHERE 1
+ ORDER BY rowid DESC");
+ $ret=array();
+ $tab = $sql->fetch_array($resql);
+ foreach ( $tab as $cle => $valeur )
+ {
+ $ret[$cle] = $valeur;
+ }
+ $tab_id_operation = $tab;
+ $id_op = $tab_id_operation['rowid'];
+
+ // Ajout d'un nouveau paiement
+ $request="INSERT INTO ".MAIN_DB_PREFIX."paiement (
+ fk_facture,
+ datec,
+ datep,
+ amount,
+ fk_paiement,
+ num_paiement,
+ note,
+ fk_bank,
+ fk_user_creat,
+ fk_user_modif,
+ statut,
+ fk_export_compta
+ )
+
+ VALUES (
+ ".$id.",
+ '".$date." ".$heure."',
+ '".$date." 12:00:00',
+ ".$obj_facturation->prix_total_ttc().",
+ ".$mode_reglement.",
+ NULL,
+ NULL,
+ $id_op,
+ ".$_SESSION['uid'].",
+ NULL,
+ 1,
+ 0
+ )";
+ $sql->query ($request);
+ // Recuperation de l'id du paiement nouvellement cr�
+ $resql=$sql->query (
+ "SELECT rowid
+ FROM ".MAIN_DB_PREFIX."paiement
+ WHERE 1
+ ORDER BY rowid DESC");
+ $ret=array();
+ $tab = $sql->fetch_array($resql);
+ foreach ( $tab as $cle => $valeur )
+ {
+ $ret[$cle] = $valeur;
+ }
+ $tab_id_paiement = $tab;
+ $id_paiement = $tab_id_paiement['rowid'];
+
+
+ $sql->query (
+ "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (
+ fk_paiement,
+ fk_facture,
+ amount
+ )
+
+ VALUES (
+ ".$id_paiement.",
+ ".$id.",
+ ".$obj_facturation->prix_total_ttc()."
+ )
+ ");
}
+ $sql->commit();
+
+
$redirection = 'affIndex.php?menu=validation_ok&facid='.$id; // Ajout de l'id de la facture, pour l'inclure dans un lien pointant directement vers celle-ci dans Dolibarr
break;
- // End of case: valide_facture
-
+ // End of case: valide_facture
}
-
$_SESSION['serObjFacturation'] = serialize ($obj_facturation);
header ('Location: '.$redirection);
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 8881212ee14..f499ac030ac 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -69,8 +69,9 @@ class Facture extends CommonObject
var $type;
var $amount;
var $remise;
- var $tva;
- var $total;
+ var $total_ht;
+ var $total_tva;
+ var $total_ttc;
var $note;
var $note_public;
//! 0=draft,
@@ -90,10 +91,10 @@ class Facture extends CommonObject
var $propalid;
var $projetid;
var $date_lim_reglement;
- var $cond_reglement_id;
- var $cond_reglement_code;
- var $mode_reglement_id;
- var $mode_reglement_code;
+ var $cond_reglement_id; // Id in llx_cond_reglement
+ var $cond_reglement_code; // Code in llx_cond_reglement
+ var $mode_reglement_id; // Id in llx_c_paiement
+ var $mode_reglement_code; // Code in llx_c_paiement
var $modelpdf;
var $products=array();
var $lignes=array();
@@ -120,8 +121,9 @@ class Facture extends CommonObject
$this->amount = 0;
$this->remise = 0;
$this->remise_percent = 0;
- $this->tva = 0;
- $this->total = 0;
+ $this->total_ht = 0;
+ $this->total_tva = 0;
+ $this->total_ttc = 0;
$this->propalid = 0;
$this->projetid = 0;
$this->remise_exceptionnelle = 0;
@@ -131,10 +133,11 @@ class Facture extends CommonObject
* \brief Create invoice in database
* \param user Object user that create
* \param notrigger 1 ne declenche pas les triggers, 0 sinon
+ * \param forceduedate Do not recalculate due date from payment condition but force it with value
* \return int <0 if KO, >0 if OK
* \remarks this->ref can be set or empty. If empty, we will use "(PROV)"
*/
- function create($user,$notrigger=0)
+ function create($user,$notrigger=0,$forceduedate=0)
{
global $langs,$conf,$mysoc;
$error=0;
@@ -190,8 +193,8 @@ class Facture extends CommonObject
$this->brouillon = 1;
}
- // Definition de la date limite
- $datelim=$this->calculate_date_lim_reglement();
+ // Define due date if not already defined
+ $datelim=(empty($forceduedate)?$this->calculate_date_lim_reglement():$forceduedate);
// Insert into database
$socid = $this->socid;
@@ -1080,7 +1083,7 @@ class Facture extends CommonObject
// 1 : ajout du nombre de jours
$datelim = $this->date + ( $cdr_nbjour * 3600 * 24 );
- // 2 : application de la r�gle "fin de mois"
+ // 2 : application de la regle "fin de mois"
if ($cdr_fdm)
{
$mois=date('m', $datelim);
@@ -1094,21 +1097,21 @@ class Facture extends CommonObject
{
$mois += 1;
}
- // On se d�place au d�but du mois suivant, et on retire un jour
+ // On se deplace au debut du mois suivant, et on retire un jour
$datelim=dol_mktime(12,0,0,$mois,1,$annee);
$datelim -= (3600 * 24);
}
- // 3 : application du d�calage
+ // 3 : application du decalage
$datelim += ( $cdr_decalage * 3600 * 24);
return $datelim;
}
/**
- * \brief Tag la facture comme pay�e compl�tement (close_code non renseign�) ou partiellement (close_code renseign�) + appel trigger BILL_PAYED
+ * \brief Tag la facture comme paye completement (close_code non renseigne) ou partiellement (close_code renseigne) + appel trigger BILL_PAYED
* \param user Objet utilisateur qui modifie
- * \param close_code Code renseign� si on classe � pay�e compl�tement alors que paiement incomplet (cas ecompte par exemple)
+ * \param close_code Code renseigne si on classe a payee completement alors que paiement incomplet (cas ecompte par exemple)
* \param close_note Commentaire renseign� si on classe � pay�e alors que paiement incomplet (cas ecompte par exemple)
* \return int <0 si ok, >0 si ok
*/
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index c134ade1cde..50a64ba04be 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -521,6 +521,7 @@ function dol_print_date($time,$format='',$to_gmt=false,$outputlangs='',$encodeto
* DD/MM/YY HH:MM:SS or DD/MM/YYYY HH:MM:SS (this format should not be used anymore)
* 19700101020000 -> 7200
* \return date Date
+ * \see dol_date, dol_mktime
*/
function dol_stringtotime($string)
{
@@ -614,7 +615,7 @@ function dolibarr_mktime($hour,$minute,$second,$month,$day,$year,$gm=0,$check=1)
* @param gm 1=Input informations are GMT values, otherwise local to user
* @param check 0=No check on parameters (Can use day 32, etc...)
* @return timestamp Date en timestamp, '' if error
- * @see dol_date
+ * @see dol_date, dol_stringtotime
*/
function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=0,$check=1)
{
@@ -673,7 +674,7 @@ function dolibarr_date($fmt, $timestamp, $gm=0)
* \param timestamp Date. Example: If timestamp=0 and gm=1, return 01/01/1970 00:00:00
* \param gm 1 if timestamp was built with gmmktime, 0 if timestamp was build with mktime
* \return string Formated date
- * \see dol_mktime
+ * \see dol_mktime, dol_stringtotime
*/
function dol_date($fmt, $timestamp, $gm=0)
{
@@ -1515,10 +1516,10 @@ function restrictedArea($user, $features='societe', $objectid=0, $dbtablename=''
//print "user_id=".$user->id.", features=".$features.", feature2=".$feature2.", object_id=".$objectid;
//print ", dbtablename=".$dbtablename.", dbt_socfield=".$dbt_keyfield.", dbt_select=".$dbt_select;
//print ", user_societe_contact_lire=".$user->rights->societe->contact->lire."
";
-
+
// More features to check
$features = explode("&",$features);
-
+
// Check read permission from module
// TODO Replace "feature" param by permission for reading
$readok=1;
@@ -1617,7 +1618,7 @@ function restrictedArea($user, $features='societe', $objectid=0, $dbtablename=''
&& empty($user->rights->$feature->write)) $createok=0;
}
}
-
+
if (! $createok) accessforbidden();
//print "Write access is ok";
}
@@ -1628,10 +1629,10 @@ function restrictedArea($user, $features='societe', $objectid=0, $dbtablename=''
foreach ($features as $feature)
{
$sql='';
-
+
// If dbtable not defined, we use same name for table than module name
if (empty($dbtablename)) $dbtablename = $feature;
-
+
// Check permission for object with entity
if ($feature == 'user' || $feature == 'usergroup' || $feature == 'produit' || $feature == 'service' || $feature == 'produit|service')
{
@@ -1698,7 +1699,7 @@ function restrictedArea($user, $features='societe', $objectid=0, $dbtablename=''
$sql.= " AND dbt.entity = ".$conf->entity;
}
}
-
+
//print $sql."
";
if ($sql)
{
@@ -3085,4 +3086,48 @@ function utf8_check($Str)
return true;
}
+
+/**
+ * \brief Return an id from a Code. Store Code-Id in a cache.
+ * \param db Database handler
+ * \param key Code to get Id
+ * \param tablename Table name without prefix
+ * \param fieldkey Field for code
+ * \param fieldid Field for id
+ * \return int Id of code
+ */
+function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id')
+{
+ global $cache_codes;
+
+ // If key empty
+ if ($key == '') return '';
+
+ // Check in cache
+ if (isset($cache_codes[$tablename][$key])) // Can be defined to 0 or ''
+ {
+ return $cache_codes[$tablename][$key]; // Found in cache
+ }
+
+ $sql = "SELECT ".$fieldid." as id";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
+ $sql.= " WHERE ".$fieldkey." = '".$key."'";
+ dol_syslog('dol_getIdFromCode sql='.$sql,LOG_DEBUG);
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $obj = $db->fetch_object($resql);
+ if ($obj) $cache_codes[$tablename][$key]=$obj->id;
+ else $cache_codes[$tablename][$key]='';
+ $db->free($resql);
+ return $cache_codes[$tablename][$key];
+ }
+ else
+ {
+ $this->error=$db->lasterror();
+ dol_syslog("dol_getIdFromCode error=".$this->error,LOG_ERR);
+ return -1;
+ }
+}
+
?>
\ No newline at end of file
diff --git a/htdocs/translate.class.php b/htdocs/translate.class.php
index 2101055eae6..4e996ca5eb4 100644
--- a/htdocs/translate.class.php
+++ b/htdocs/translate.class.php
@@ -575,7 +575,7 @@ class Translate {
/**
- * \brief Return full text translated to languagea label for a key. Store key-label in a cache.
+ * \brief Return full text translated to language label for a key. Store key-label in a cache.
* \number number Number to encode in full text
* \param isamount 1=It's an amount, 0=it's just a number
* \return string Label translated in UTF8 (but without entities)
@@ -617,7 +617,6 @@ class Translate {
* \param tablename Table name without prefix
* \param fieldkey Field for key
* \param fieldlabel Field for label
- * \param fieldval Value to find record
* \return string Label in UTF8 (but without entities)
* \remarks This function can be used to get label in database but more often to get code from key id.
*/