forked from Wavyzz/dolibarr
A lot of fix on point of sale module
This commit is contained in:
@@ -47,8 +47,8 @@ class Sql implements intSql {
|
||||
// }
|
||||
|
||||
/**
|
||||
* Effectue une requ<EFBFBD>te sur la base de donn<6E>es, et renvoi la ressource correspondante
|
||||
* @param $aRequete Requ<EFBFBD>te SQL (ex : SELECT nom, prenom FROM table1 WHERE id = 127)
|
||||
* Effectue une requete sur la base de donn<6E>es, et renvoi la ressource correspondante
|
||||
* @param $aRequete Requete SQL (ex : SELECT nom, prenom FROM table1 WHERE id = 127)
|
||||
* @return Ressource vers la requ<71>te venant d'<27>tre effectu<74>e
|
||||
*/
|
||||
public function query ($aRequete) {
|
||||
|
||||
@@ -17,21 +17,25 @@
|
||||
* 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');
|
||||
|
||||
$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)
|
||||
{
|
||||
while ( $tab = $sql->fetch_array($resql) )
|
||||
{
|
||||
foreach ( $tab as $cle => $valeur )
|
||||
@@ -40,18 +44,25 @@ if ( $_GET['filtre'] ) {
|
||||
}
|
||||
$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 )
|
||||
|
||||
@@ -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) ) {
|
||||
|
||||
|
||||
@@ -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;
|
||||
?>
|
||||
|
||||
@@ -61,7 +61,6 @@ function afficheDonnees (aId, aTexte) {
|
||||
|
||||
// aCible : id du bloc de destination; aCode : argument <20> passer <20> la page php charg<72>e du traitement et de l'affichage
|
||||
function verifResultat (aCible, aCode) {
|
||||
|
||||
if (aCode != '') {
|
||||
|
||||
if (texte = file ('facturation_dhtml.php?code='+escape(aCode))) {
|
||||
|
||||
@@ -26,10 +26,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
<?php
|
||||
// Recuperation du contenu de la vente
|
||||
$res = $sql->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;
|
||||
|
||||
@@ -48,32 +48,24 @@ switch ( $_GET['action'] )
|
||||
|
||||
$obj_facturation->mode_reglement ($_POST['hdnChoix']);
|
||||
|
||||
// Si paiement autre qu'en esp<EFBFBD>ces, montant encaiss<EFBFBD> = 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<EFBFBD>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<63>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'<27>ch<63>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<63>
|
||||
$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<63>
|
||||
$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
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$_SESSION['serObjFacturation'] = serialize ($obj_facturation);
|
||||
|
||||
header ('Location: '.$redirection);
|
||||
|
||||
@@ -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<EFBFBD>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<EFBFBD>place au d<EFBFBD>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<EFBFBD>calage
|
||||
// 3 : application du decalage
|
||||
$datelim += ( $cdr_decalage * 3600 * 24);
|
||||
|
||||
return $datelim;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Tag la facture comme pay<EFBFBD>e compl<EFBFBD>tement (close_code non renseign<EFBFBD>) ou partiellement (close_code renseign<EFBFBD>) + 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<EFBFBD> si on classe <EFBFBD> pay<EFBFBD>e compl<EFBFBD>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<67> si on classe <20> pay<61>e alors que paiement incomplet (cas ecompte par exemple)
|
||||
* \return int <0 si ok, >0 si ok
|
||||
*/
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user