A lot of fix on point of sale module

This commit is contained in:
Laurent Destailleur 2009-10-22 00:27:13 +00:00
parent 8c2705707a
commit 3cb6df16fd
9 changed files with 143 additions and 190 deletions

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
@ -49,12 +49,14 @@ $langs->load("@cashdesk");
if ($_POST["action"] == 'set')
{
if ($_POST["CASHDESK_ID_THIRDPARTY"] < 0) $_POST["CASHDESK_ID_THIRDPARTY"]='';
if ($_POST["CASHDESK_ID_WAREHOUSE"] < 0) $_POST["CASHDESK_ID_WAREHOUSE"]='';
if ($_POST["CASHDESK_ID_BANKACCOUNT"] < 0) $_POST["CASHDESK_ID_BANKACCOUNT"]='';
// if ($_POST["CASHDESK_ID_WAREHOUSE"] < 0) $_POST["CASHDESK_ID_WAREHOUSE"]='';
dolibarr_set_const($db,"CASHDESK_ID_THIRDPARTY",$_POST["CASHDESK_ID_THIRDPARTY"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db,"CASHDESK_ID_BANKACCOUNT",$_POST["CASHDESK_ID_BANKACCOUNT"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db,"CASHDESK_ID_WAREHOUSE",$_POST["CASHDESK_ID_WAREHOUSE"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db,"CASHDESK_ID_BANKACCOUNT_CASH",$_POST["CASHDESK_ID_BANKACCOUNT_CASH"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db,"CASHDESK_ID_BANKACCOUNT_CHEQUE",$_POST["CASHDESK_ID_BANKACCOUNT_CHEQUE"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db,"CASHDESK_ID_BANKACCOUNT_CB",$_POST["CASHDESK_ID_BANKACCOUNT_CB"],'chaine',0,'',$conf->entity);
// dolibarr_set_const($db,"CASHDESK_ID_WAREHOUSE",$_POST["CASHDESK_ID_WAREHOUSE"],'chaine',0,'',$conf->entity);
dol_syslog("admin/cashdesk: level ".$_POST["level"]);
}
@ -96,9 +98,22 @@ if ($conf->global->MAIN_MODULE_BANQUE)
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("CashDeskBankAccountForSell").'</td>';
print '<td colspan="2">';
$form->select_comptes($conf->global->CASHDESK_ID_BANKACCOUNT,'CASHDESK_ID_BANKACCOUNT',0,"courant=2",1);
$form->select_comptes($conf->global->CASHDESK_ID_BANKACCOUNT_CASH,'CASHDESK_ID_BANKACCOUNT_CASH',0,"courant=2",1);
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("CashDeskBankAccountForCheque").'</td>';
print '<td colspan="2">';
$form->select_comptes($conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE,'CASHDESK_ID_BANKACCOUNT_CHEQUE',0,"courant=1",1);
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("CashDeskBankAccountForCB").'</td>';
print '<td colspan="2">';
$form->select_comptes($conf->global->CASHDESK_ID_BANKACCOUNT_CB,'CASHDESK_ID_BANKACCOUNT_CB',0,"courant=1",1);
print '</td></tr>';
}
/*
if ($conf->global->MAIN_MODULE_STOCK)
{
$var=!$var;
@ -107,7 +122,7 @@ if ($conf->global->MAIN_MODULE_STOCK)
$formproduct->selectWarehouses($conf->global->CASHDESK_ID_WAREHOUSE,'CASHDESK_ID_WAREHOUSE','',1);
print '</td></tr>';
}
*/
print '</table>';

View File

@ -39,7 +39,11 @@ $conf_url_racine = $dolibarr_main_url_root.'/cashdesk';
// Identifiant unique correspondant au tiers generique pour la vente
$conf_fksoc = $conf->global->CASHDESK_ID_THIRDPARTY;
// Identifiant unique correspondant au compte caisse / liquide
$conf_fkaccount = $conf->global->CASHDESK_ID_BANKACCOUNT > 0?$conf->global->CASHDESK_ID_BANKACCOUNT:$_SESSION["CASHDESK_ID_BANKACCOUNT"];
$conf_fkaccount_cash = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH > 0?$conf->global->CASHDESK_ID_BANKACCOUNT_CASH:$_SESSION["CASHDESK_ID_BANKACCOUNT_CASH"];
// Identifiant unique correspondant au compte cheque
$conf_fkaccount_cheque = $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE > 0?$conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE:$_SESSION["CASHDESK_ID_BANKACCOUNT_CHEQUE"];
// Identifiant unique correspondant au compte cb
$conf_fkaccount_cb = $conf->global->CASHDESK_ID_BANKACCOUNT_CB > 0?$conf->global->CASHDESK_ID_BANKACCOUNT_CB:$_SESSION["CASHDESK_ID_BANKACCOUNT_CB"];
// Identifiant unique correspondant a l'entrepot associe a la caisse
$conf_fkentrepot = $conf->global->CASHDESK_ID_WAREHOUSE > 0?$conf->global->CASHDESK_ID_WAREHOUSE:$_SESSION["CASHDESK_ID_WAREHOUSE"];

View File

@ -27,9 +27,10 @@ $company->fetch($conf->global->CASHDESK_ID_THIRDPARTY);
$bank=new Account($db);
$bank->fetch($conf->global->CASHDESK_ID_BANKACCOUNT);
$warehouse=new Entrepot($db);
$warehouse->fetch($conf->global->CASHDESK_ID_WAREHOUSE);
//$warehouse->fetch($conf->global->CASHDESK_ID_WAREHOUSE);
$langs->load("@cashdesk");
$langs->load("main");
$logout='<img class="login" border="0" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/logout.png">';
@ -42,7 +43,7 @@ print '<li class="menu_choix2"><a href=".."><span>'.$langs->trans("BackOffice").
print '<li class="menu_choix0">'.$langs->trans("User").' : '.$_SESSION['prenom'].' '.$_SESSION['nom'].' <a href="deconnexion.php">'.$logout.'</a><br>';
print $langs->trans("CashDeskThirdParty").' : '.$company->getNomUrl(1).'<br>';
print $langs->trans("CashDeskBank").' : '.$bank->getNomUrl(1).'<br>';
if ($conf->stock->enabled)
if ($conf->stock->enabled && $warehouse->id) // Disabled because warehouse->fetch disabled before
{
print $langs->trans("CashDeskWarehouse").' : '.$warehouse->getNomUrl(1);
}

View File

@ -20,7 +20,9 @@
require ('../master.inc.php');
require (DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php');
require (DOL_DOCUMENT_ROOT.'/cashdesk/classes/Facturation.class.php');
require (DOL_DOCUMENT_ROOT.'/Facture.class.php');
require (DOL_DOCUMENT_ROOT.'/facture.class.php');
require (DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php');
require (DOL_DOCUMENT_ROOT.'/paiement.class.php');
$obj_facturation = unserialize ($_SESSION['serObjFacturation']);
unset ($_SESSION['serObjFacturation']);
@ -85,16 +87,21 @@ switch ( $_GET['action'] )
$heure = date ('H:i:s');
$note = '';
if (! is_object($obj_facturation))
{
dol_print_error('','Empty context');
exit;
}
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 = dol_getIdFromCode($sql,'RECEP','cond_reglement','code','rowid')
$cond_reglement_id = 0;
break;
case 'ESP':
$mode_reglement_id = dol_getIdFromCode($db,$obj_facturation->mode_reglement(),'c_paiement');
$mode_reglement_id = dol_getIdFromCode($sql,'LIQ','c_paiement');
$cond_reglement_id = 0;
$note .= $langs->trans("Cash")."\n";
$note .= $langs->trans("Received").' : '.$obj_facturation->montant_encaisse()." ".$conf->monnaie."\n";
@ -103,19 +110,23 @@ switch ( $_GET['action'] )
$note .= '--------------------------------------'."\n\n";
break;
case 'CB':
$mode_reglement_id = dol_getIdFromCode($db,$obj_facturation->mode_reglement(),'c_paiement');
$mode_reglement_id = dol_getIdFromCode($sql,'CB','c_paiement');
$cond_reglement_id = 0;
break;
case 'CHQ':
$mode_reglement_id = dol_getIdFromCode($db,$obj_facturation->mode_reglement(),'c_paiement');
$mode_reglement_id = dol_getIdFromCode($sql,'CHQ','c_paiement');
$cond_reglement_id = 0;
break;
}
// ... on termine la note
if (empty($mode_reglement_id)) $mode_reglement_id=0; // If mode_reglement_id not found
if (empty($cond_reglement_id)) $cond_reglement_id=0; // If cond_reglement_id not found
$note .= $_POST['txtaNotes'];
dol_syslog("obj_facturation->mode_reglement()=".$obj_facturation->mode_reglement()." mode_reglement_id=".$mode_reglement_id." cond_reglement_id=".$cond_reglement_id);
$error=0;
$now=dol_now('tzserver');
$sql->begin();
@ -123,7 +134,6 @@ switch ( $_GET['action'] )
$user->fetch();
$user->getrights();
$now=dol_now('tzserver');
$invoice=new Facture($sql,$conf_fksoc);
@ -182,60 +192,6 @@ switch ( $_GET['action'] )
$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'];
// Calcul de la position de l'article dans la liste
$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 (
'INSERT INTO '.MAIN_DB_PREFIX.'facturedet (
fk_facture,
fk_product,
description,
tva_taux,
qty,
remise_percent,
remise,
fk_remise_except,
subprice,
price,
total_ht,
total_tva,
total_ttc,
date_start,
date_end,
info_bits,
fk_code_ventilation,
fk_export_compta,
rang
)
VALUES (
'.$id.",
".$tab_liste[$i]['fk_article'].",
'".$tab_article['label']."',
".$tab_tva['taux'].",
".$tab_liste[$i]['qte'].",
".$tab_liste[$i]['remise_percent'].",
".$tab_liste[$i]['remise'].",
0,
".$tab_article['price'].",
".$tab_article['price'].",
".$tab_liste[$i]['total_ht'].",
".$montant_tva.",
".$tab_liste[$i]['total_ttc'].",
NULL,
NULL,
0,
0,
0,
".$position.")");
*/
}
$invoice->socid=$conf_fksoc;
@ -266,122 +222,97 @@ switch ( $_GET['action'] )
$id = $invoice->id;
// Add the payment
// TODO Manage ESP, CHQ...
$payment=new Paiement($db);
$payment->datepaye=$now;
$payment->bank_account=$conf_fkaccount;
$payment->amounts[$invoice->id]=$obj_facturation->prix_total_ttc();
$payment->note=$langs->trans("Payment").' '.$langs->trans("Invoice").' '.$obj_facturation->num_facture();
$payment->paiementid=$invoice->mode_reglement_id;
$payment->num_paiement='';
// Ajout d'une operation sur le compte de caisse, uniquement si le paiement est en especes
if ( $obj_facturation->mode_reglement() == 'ESP' )
$paiement_id = $payment->create($user);
if ($paiement_id > 0)
{
$sql->query (
"INSERT INTO ".MAIN_DB_PREFIX."bank (
datec,
datev,
dateo,
amount,
label,
fk_account,
fk_user_author,
fk_type,
rappro,
fk_bordereau
)
// Ajout d'une ecriture sur le compte bancaire
if ($conf->banque->enabled)
{
$bankaccountid=0;
if ( $obj_facturation->mode_reglement() == 'ESP' )
{
$bankaccountid=$conf_fkaccount_cash;
}
if ( $obj_facturation->mode_reglement() == 'CHQ' )
{
$bankaccountid=$conf_fkaccount_cheque;
}
if ( $obj_facturation->mode_reglement() == 'CB' )
{
$bankaccountid=$conf_fkaccount_cb;
}
VALUES (
'".$date." ".$heure."',
'".$date."',
'".$date."',
".$obj_facturation->prix_total_ttc().",
'Paiement caisse facture ".$obj_facturation->num_facture()."',
".$conf_fkaccount.",
".$_SESSION['uid'].",
'ESP',
0,
0
)
");
if ($bankaccountid > 0)
{
// Insertion dans llx_bank
$label = "(CustomerInvoicePayment)";
$acc = new Account($db, $bankaccountid);
$bank_line_id = $acc->addline($payment->datepaye,
$payment->paiementid, // Payment mode id or code ("CHQ or VIR for example")
$label,
$obj_facturation->prix_total_ttc(),
$payment->num_paiement,
'',
$user,
'',
'');
// Mise a jour fk_bank dans llx_paiement.
// On connait ainsi le paiement qui a genere l'ecriture bancaire
if ($bank_line_id > 0)
{
$payment->update_fk_bank($bank_line_id);
// Mise a jour liens (pour chaque facture concernees par le paiement)
foreach ($payment->amounts as $key => $value)
{
$facid = $key;
$fac = new Facture($db);
$fac->fetch($facid);
$fac->fetch_client();
$acc->add_url_line($bank_line_id,
$paiement_id,
DOL_URL_ROOT.'/compta/paiement/fiche.php?id=',
'(paiement)',
'payment');
$acc->add_url_line($bank_line_id,
$fac->client->id,
DOL_URL_ROOT.'/compta/fiche.php?socid=',
$fac->client->nom,
'company');
}
}
else
{
$error++;
}
}
}
}
// 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 )
else
{
$ret[$cle] = $valeur;
$error++;
}
$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
if (! $error)
{
$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
}
else
{
$sql->rollback();
$redirection = 'affIndex.php?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

View File

@ -59,7 +59,7 @@ if ($_POST['action'] == 'add_paiement' || $_POST['action'] == 'confirm_paiement'
$_POST['reyear']);
$paiement_id = 0;
// Verifie si des paiements sont sup<EFBFBD>rieurs au montant facture
// Verifie si des paiements sont superieurs au montant facture
foreach ($_POST as $key => $value)
{
if (substr($key,0,7) == 'amount_')
@ -93,8 +93,8 @@ if ($_POST['action'] == 'add_paiement' || $_POST['action'] == 'confirm_paiement'
// d'un paiement
if (! $_POST['accountid'])
{
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
$error++;
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
$error++;
}
}
@ -155,9 +155,9 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
// Insertion dans llx_bank
$label = "(CustomerInvoicePayment)";
$acc = new Account($db, $_POST['accountid']);
//paiementid contient "CHQ ou VIR par exemple"
$bank_line_id = $acc->addline($paiement->datepaye,
$paiement->paiementid,
$paiement->paiementid, // Payment mode id or code ("CHQ or VIR for example")
$label,
$totalpaiement,
$paiement->num_paiement,
@ -167,7 +167,7 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes')
$_POST['chqbank']);
// Mise a jour fk_bank dans llx_paiement.
// On connait ainsi le paiement qui a g<EFBFBD>n<EFBFBD>r<EFBFBD> l'<27>criture bancaire
// On connait ainsi le paiement qui a genere l'ecriture bancaire
if ($bank_line_id > 0)
{
$paiement->update_fk_bank($bank_line_id);

View File

@ -56,8 +56,7 @@ class modCashDesk extends DolibarrModules
$this->description = "CashDesk module";
$this->revision = explode(' ','$Revision$');
$this->version = 'experimental';
//$this->version = 'experimental'; // 'development' or 'experimental' or 'dolibarr' or version
$this->version = 'dolibarr';
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
$this->special = 0;

View File

@ -1093,7 +1093,9 @@ ClickToDialDesc=This module allows to add an icon after the phone number of Doli
CashDesk=Point of sales
CashDeskSetup=Point of sales module setup
CashDeskThirdPartyForSell=Generic third party to use for sells
CashDeskBankAccountForSell=Cash account to use for sells
CashDeskBankAccountForSell=Account to use to receive cash payments
CashDeskBankAccountForCheque = Account to use to receive payments by cheque
CashDeskBankAccountForCB = Account to use to receive cash payments by credit cards
CashDeskIdWareHouse=Warehouse to use for sells
##### Bookmark #####
BookmarkSetup=Bookmark module setup

View File

@ -1093,7 +1093,9 @@ ClickToDialDesc = Ce module permet d'ajouter un petit picto a coté des numéros
CashDesk=Caisse enregistreuse
CashDeskSetup = Configuration du module Caisse enregistreuse
CashDeskThirdPartyForSell = Tiers générique à utiliser pour les ventes
CashDeskBankAccountForSell = Compte caisse à utiliser pour les ventes
CashDeskBankAccountForSell = Compte à utiliser pour l'encaissement en liquide (cash)
CashDeskBankAccountForCheque = Compte à utiliser pour l'encaissement en chèque
CashDeskBankAccountForCB = Compte à utiliser pour l'encaissement par carte de crédit
CashDeskIdWareHouse = Entrepot à utiliser pour les ventes
##### Bookmark ##### = undefined
BookmarkSetup = Configuration du module Bookmark

View File

@ -3124,8 +3124,7 @@ function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id')
}
else
{
$this->error=$db->lasterror();
dol_syslog("dol_getIdFromCode error=".$this->error,LOG_ERR);
dol_syslog("dol_getIdFromCode error=".$db->lasterror(),LOG_ERR);
return -1;
}
}