Fix bug in annulation, add check to validate number and card

This commit is contained in:
sparkyx 2004-04-03 00:21:24 +00:00
parent dd6b037a47
commit c2179cab14
10 changed files with 249 additions and 70 deletions

View file

@ -1,5 +1,31 @@
2004-04-02 sparkyx <sparkyx@july.summer>
* html/annulation.php, include/central_inc.php:
Change cancel an op : j_internal=='ANNULE' and jr_internal of the cancel operation = 'ANNULE'
* html/annulation.php, include/central_inc.php, include/jrn.php:
Change centralize and jr_internal rule
* html/modify_op.php, include/jrn.php: Payment
* include/stock_inc.php: Stock include file
* html/annulation.php, html/fiche_new.php, html/fiche_search.php, html/jrn_search.php, html/login.php, html/print_balance.php, html/stock.php, html/user_login.php, include/constant.php, include/form_input.php, include/jrn.php, include/postgres.php, include/user_common.php, include/user_menu.php, sql/account_repository.sql, sql/demo.sql, sql/mod-be.sql, FAQ-fr.txt, doc/FAQ-fr.txt, doc/manuel-fr.sgml, html/admin_repo.php, style-light.css:
Many little Bugs fixed
2004-04-01 sparkyx <sparkyx@july.summer>
* include/form_input.php, include/user_action_fin.php, include/user_action_ods.php:
Improve appearance in user interface for ach, ven, fin and ods
* include/compta_menu.php, include/fiche_inc.php, include/form_input.php, include/jrn.php, include/user_common.php:
code cleaning
* include/form_inc.php, html/enc_jrn.php, html/jrn_add.php, html/jrn_detail.php, html/jrn_search.php, html/poste_search.php, html/win_detail_jrn.js, html/win_search_jrn.js, html/win_search_poste.js:
remove javascript file, the javascript are now in include/constant.php (define JS_)
* Changelog: Update
* sql/dump-db.sql: script for creating db files
* include/jrn.php: Adapt for new features (ODS, UpdateJrn...)

View file

@ -176,15 +176,51 @@ passe pas par des comptes d
</sect2>
</sect1>
<sect1> Fiscalité, TVA
<p> tous les requalifications des montants doivent
se faire par le journal des opérations diverses
<sect2> Belgique
<sect3> TVA & impôt
<p> Pour faire votre déclaration tva, vous pouvez utilisez les
balances des comptes ou les formulaires.
<p>
Attention NE PAS REPRENDRE LES
MONTANTS AINSI !!!. Avant de faire votre déclaration, vous devez d'abord
rectifier les montants. Par exemple, 50% de la tva sur la voiture ne
sont pas récupérable par la tva mais par l'impôt des société.
Il faut "déplacer" 50% de cette tva dans un poste comptable tva non
admises,
cela devrait être un compte de la classe 6 (donc 6xxxx à 411xxx), les charges
augmentent mais la tva à récupérer diminue, ce qui est logique puisque
cette tva est à récupérer par l'impôt des sociétés.
<p> Idem pour les frais de restaurant, ne pas oublier pendant les
travaux de fin d'exercice,d'imputer 50% du total de vos frais de
restaurant à un compte de dépense non admise. Il n'est pas dans le
PCMN donc créer le poste vous-même (classe 67).
<p>De plus si vous utilisez la voiture pour votre usage personnel, 2/7
doivent être mis sur le compte exploitant dans le cas d'une
sprl. C'est-à-dire qu'il
faut diminuer les charges 6xxxx frais de voiture à 41xxx Compte de
l'exploitant. Et de la même manière, diminuer la tva de vos frais de
voiture de 2/7.
</sect3>
<sect2> France
<p> Pas reçu de doc ni d'aide sur ce sujet désolé
</sect2>
</sect1>
</sect>
<sect> Les profils
<sect> Les modes
<p>
Dans le menu préférence, il existe deux sortes d'interface que vous pouvez utiliser,
</p>
<sect1>Le profil comptable
<sect1>Le mode comptable
<p>
Dans ce cas, vous verrez votre comptabilité comme un comptable s'attend à la voir
avec des postes comptables, des écritures comptables impliquant des
@ -196,7 +232,7 @@ r
mal encodé, vous devez introduire l'écriture comptable inverse pour
corriger, pensez à mettre la mention "correction d'erreur"
</sect1>
<sect1>Le profil utilisateur
<sect1>Le mode utilisateur
<p>
Dans ce cas, vous verrez votre comptabilité comme un utilisateur, facture à payer, facture à encoder...
@ -246,6 +282,12 @@ exemple :
Ceux qui terminent par une étoile reprennent les comptes qui commence
par l'expression ainsi 411* reprendra 411, 4111, 4112,4113 et
4114. Vous séparez les différents comptes par un espace.
Il vaut mieux ne pas créer plus de 4 journaux par types, c'est-à-dire
16 au total, il y a à cela deux raisons : la première est que cela
devient ingérable, la seconde est que l'affichage en mode utilisateur
serait euh... atroce. Quatre journaux en tout est largement suffisant
pour les besoins d'une entreprise.
<sect1> Journal des Achats
</sect1>
<sect1> Journal des Ventes
@ -288,7 +330,10 @@ vous devrez mettre manuellement le poste comptable
</sect1>
<sect1>Création d'une fiche
<p>
Quelques attributs à expliquer : Gestion Poste, Prix Achat, Prix de vente, Poste Comptable
Quelques attributs à expliquer : Gestion Poste, Prix Achat, Prix de
vente, Poste Comptable. Vous n'êtes pas obligé de créer une fiche pour
tout, par exemple pour les restaurants, vous pouvez encodez une seule
et unique fiche appelée restaurant.
</p>
</sect1>
@ -507,6 +552,5 @@ encoder dans le journal financier, ne pas oublier le rapprochement
Banque : le client nous a payé pour la facture du 21
encoder dans le journal financier, ne pas oublier le rapprochement
</sect1>
</sect>
</article>

View file

@ -55,9 +55,10 @@ if ( isset ($annul) ) {
if ( isset ($_POST['p_id'])) {
// Get the current periode
$period=GetUserPeriode($cn,$g_user);
$p_id=$_POST['p_id'];
// Check if it a centralize operation
if ( isCentralize($cn,$p_id) == 0 ) {
if ( isCentralize($cn,$p_id) == 0 and
isValid($cn,$p_id) == 1 ) {
// get the next op id
$seq=GetNextId($cn,'j_grpt')+1;
@ -69,33 +70,35 @@ if ( isset ($annul) ) {
)
select
j_montant, j_poste, $seq, j_jrn_def, case when j_debit=false then true else false end,
j_text,'ANNULE,'$g_user',$period
j_text,'ANNULE','$g_user',$period
from jrnx where j_grpt=".$_POST['p_id'];
$Res=ExecSql($cn,$sql);
// build the sql stmt for jrn
$sql= "insert into jrn (
jr_def_id,jr_montant,jr_comment, jr_date,jr_grpt_id,jr_internal ,jr_tech_per
jr_def_id,jr_montant,jr_comment, jr_date,jr_grpt_id,jr_internal ,jr_tech_per,
jr_valid
) select
jr_def_id,jr_montant,'Annulation '||jr_comment,jr_date,$seq ,'ANNULE', $period
jr_def_id,jr_montant,'Annulation '||jr_comment,jr_date,$seq ,'ANNULE', $period,
false
from
jrn
where jr_grpt_id=".$_POST['p_id'];
$Res=ExecSql($cn,$sql);
// also in the stock table
$sql="insert into stock_goods (
j_id,f_id,sg_quantity,sg_type
) select
j_id,f_id,sg_quantity, case when sg_type='c' then 'd' else 'c' end
from stock_goods natural join jrnx where j_grpt=".$_POST['p_id'];
$sql="delete from stock_goods where sg_id = any ( select sg_id
from stock_goods natural join jrnx where j_grpt=".$_POST['p_id'].")";
$Res=ExecSql($cn,$sql);
// Update jr_valid
$Res=ExecSql($cn,"update jrn set jr_valid=false where jr_grpt_id=$p_id");
echo '<h2 class="info"> Opération annulée</h2>';
}
echo '<h2 class="info"> Opération annulée</h2>';
?>
<script>
window.close();
window.close();
self.opener.RefreshMe();
</script>
<?

View file

@ -279,7 +279,7 @@ function cal()
);
// Sql string
define ("SQL_LIST_ALL_INVOICE","");
define ("SQL_LIST_UNPAID_INVOICE"," where (jr_rapt is null or jr_rapt = '')");
define ("SQL_LIST_UNPAID_INVOICE"," where (jr_rapt is null or jr_rapt = '') and jr_valid = true ");
define ("SQL_LIST_UNPAID_INVOICE_DATE_LIMIT" ," where (jr_rapt is null or jr_rapt = '')
and to_date(to_char(jr_ech,'DD.MM.YYYY'),'DD.MM.YYYY') < to_date(to_char(now(),'DD.MM.YYYY'),'DD.MM.YYYY')");
and to_date(to_char(jr_ech,'DD.MM.YYYY'),'DD.MM.YYYY') < to_date(to_char(now(),'DD.MM.YYYY'),'DD.MM.YYYY') and jr_valid = true" );
?>

View file

@ -737,7 +737,6 @@ function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p
// Save old value and set a new one
$e_client=( isset ($e_client) )?$e_client:"";
// $r.='<TR>'.InputType("Fournisseur","SELECT","e_client",$customer,$view_only,$fiche).'</TR>';
$e_client_label="";
@ -790,6 +789,7 @@ function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p
echo_error($msg); echo_error($msg);
echo "<SCRIPT>alert('$msg');</SCRIPT>";
$march_buy=0;
if ( $view_only ) return null;
}
$march_tva_label="";
$march_label="";
@ -801,6 +801,7 @@ function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p
echo_error($msg); echo_error($msg);
echo "<SCRIPT>alert('$msg');</SCRIPT>";
$march="";
if ( $view_only ) return null;
} else {
// retrieve the tva label and name
$a_fiche=GetFicheAttribut($p_cn, $march);
@ -809,6 +810,13 @@ function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p
$march_label=$a_fiche['vw_name'];
}
}
} else {
if ( $view_only ) {
$msg="Fiche inexistante !!! ";
echo_error($msg); echo_error($msg);
echo "<SCRIPT>alert('$msg');</SCRIPT>";
return null;
}
}
$r.='<TR>'.InputType("","js_search","e_march".$i,$march,$view_only,'deb');
$r.=InputType("","span", "e_march".$i."_label", $march_label,$view_only);
@ -923,7 +931,7 @@ function RecordAchat($p_cn,$p_array,$p_user,$p_jrn)
$j_id=InsertJrnx($p_cn,'d',$p_user,$p_jrn,$poste,$e_date,$a_price[$i]*$a_quant[$i],$seq,$periode);
// if ( withStock($p_cn,$a_good[$i]) == true )
// always save quantity but in withStock we can find what card need a stock management
InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'c');
InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'d');
}
// Insert Vat
if (sizeof($a_vat) != 0 ) // no vat
@ -934,14 +942,16 @@ function RecordAchat($p_cn,$p_array,$p_user,$p_jrn)
}
}
echo_debug("echeance = $e_ech");
InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"",$amount+$sum_vat,$seq,$periode);
// Set Internal code and Comment
$comment=SetInternalCode($p_cn,$seq,$p_jrn)." client : ".GetFicheName($p_cn,$e_client);
if ( $e_comment=="" ) {
// Update comment if comment is blank
$Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq);
if ( ($amount+$sum_vat) != 0 ){
InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"",$amount+$sum_vat,$seq,$periode);
// Set Internal code and Comment
$comment=SetInternalCode($p_cn,$seq,$p_jrn)." client : ".GetFicheName($p_cn,$e_client);
if ( $e_comment=="" ) {
// Update comment if comment is blank
$Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq);
}
return $comment;
}
return $comment;
}
/* function FormFin($p_cn,$p_jrn,$p_user,$p_array=null,$view_only=true,$p_item=1)
@ -1007,16 +1017,25 @@ function FormFin($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p
// retrieve e_bank_account_label
if ( isNumber($e_bank_account) == 1 ) {
if ( isFicheOfJrn($p_cn,$p_jrn,$e_bank_account,'cred') == 0 ) {
if ( isFicheOfJrn($p_cn,$p_jrn,$e_bank_account,'deb') == 0 ) {
$msg="Fiche inexistante !!! ";
echo_error($msg); echo_error($msg);
echo "<SCRIPT>alert('$msg');</SCRIPT>";
$e_bank_account="";
echo_debug("FormFin returns NULL the bank account is not valid");
return null;
} else {
$a_client=GetFicheAttribut($p_cn,$e_bank_account);
if ( $a_client != null)
$e_bank_account_label=$a_client['vw_name']." adresse ".$a_client['vw_addr']." ".$a_client['vw_cp'];
}
}else {
if ( $view_only ==true) {
return null;
echo_debug("FormFin returns NULL the bank account is not valid");
}
}
$r.='<TR>'.InputType("Banque","js_search","e_bank_account",$e_bank_account,$view_only,FICHE_TYPE_FIN).'</TR>';
@ -1062,7 +1081,7 @@ function FormFin($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p
$tiers_comment=(isset (${"e_other$i"."_comment"}))?${"e_other$i"."_comment"}:"";
// If $tiers has a value
if ( isNumber($tiers) == 1 ) {
if ( isFicheOfJrn($p_cn,$p_jrn,$tiers,'deb') == 0 ) {
if ( isFicheOfJrn($p_cn,$p_jrn,$tiers,'cred') == 0 ) {
$msg="Fiche inexistante !!! ";
echo_error($msg); echo_error($msg);
echo "<SCRIPT>alert('$msg');</SCRIPT>";
@ -1078,7 +1097,7 @@ function FormFin($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p
${"e_other$i"."_amount"}=(isset (${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:0;
// Compute the string to pass to InputType
$f=FICHE_TYPE_CLIENT.",".FICHE_TYPE_FOURNISSEUR.",".FICHE_TYPE_ADM_TAX.",".FICHE_TYPE_FIN;
$r.='<TR>'.InputType("","js_search","e_other".$i,$tiers,$view_only,$f);
$r.='<TR>'.InputType("","js_search","e_other".$i,$tiers,$view_only,'cred');
$r.=InputType("","span", "e_other$i"."_label", $tiers_label,$view_only);
// Comment
$r.=InputType("","Text","e_other$i"."_comment",$tiers_comment,$view_only);
@ -1123,7 +1142,7 @@ return $r;
* true on success
*/
function RecordFin($p_cn,$p_array,$p_user,$p_jrn) {
echo_debug("RecordFin");
foreach ( $p_array as $v => $e)
{
${"$v"}=$e;
@ -1186,7 +1205,7 @@ function RecordFin($p_cn,$p_array,$p_user,$p_jrn) {
$Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq);
}
}
return $comment;
}
/* function FormODS($p_cn,$p_jrn,$p_user,$p_array=null,$view_only=true,$p_article=1)
* Purpose : Display the miscellaneous operation

View file

@ -968,7 +968,7 @@ function NextJrn($p_cn,$p_type)
*/
function SetInternalCode($p_cn,$p_grpt,$p_jrn)
{
$num=CountSql($p_cn,"select * from jrn where jr_def_id=$p_jrn where jr_internal != 'ANNULE'");
$num=CountSql($p_cn,"select * from jrn where jr_def_id=$p_jrn and jr_internal != 'ANNULE'");
$atype=GetJrnProperty($p_cn,$p_jrn);
$type=$atype['jrn_def_code'];
$internal_code=sprintf("%s-%05d",$type,$num);

View file

@ -31,29 +31,23 @@
* return: string containing the table
*/
function ViewStock($p_cn,$p_year) {
// build sql
$sql= 'select C.sg_code,sum(deb) as deb_sum,sum(cred) as cred_sum
from jrnx
// build sql
$sql=" select C.sg_code,sum(deb) as deb_sum,sum(cred) as cred_sum
from jrnx
join stock_goods using (j_id)
join
( select sg_code,
case when sg_type=\'d\' then sg_quantity else 0 end as deb,
case when sg_type=\'c\' then sg_quantity else 0 end as cred
from stock_goods
( select sg_code,j_id,
case when sg_type='d' then sg_quantity else 0 end as deb,
case when sg_type='c' then sg_quantity else 0 end as cred
from stock_goods
where sg_code is not null
) as C on (stock_goods.sg_code=C.sg_code)
left outer join (select f_id,av_text as name
from jnt_fic_att_value join attr_value using (jft_id) where ad_id='.ATTR_DEF_NAME.'
) as B on stock_goods.f_id=B.f_id
and sg_code != 'null'
) as C on (jrnx.j_id=C.j_id)
where
to_char(j_date,'YYYY') = '$p_year'
group by c.sg_code";
where
to_char(j_date,\'YYYY\') = \''.$p_year.'\'
group by c.sg_code
';
// send the sql
$Res=ExecSql($p_cn,$sql);
@ -61,7 +55,8 @@ group by c.sg_code
// store it in a HTLM table
$result="<table>";
$result.="<tr>";
$result.='<th>Nom</th>';
$result.='<th>Code</th>';
$result.='<th>Noms</th>';
$result.='<th>Entrée</th>';
$result.='<th>Sortie</th>';
$result.='<th>Solde</th>';
@ -71,23 +66,41 @@ group by c.sg_code
for ($i = 0; $i < $M ; $i++ ) {
$r=pg_fetch_array($Res,$i);
$result.="<TR>";
// name and link to details
/* $result.="<td>".'<a class="one"
HREF="stock.php?action=detail&f_id='.$r['f_id'].'&year='.$p_year.'">'.
$r['name']."</A></td>";
*/
// sg_code and link to details
$result.="<td>".'<a class="one"
HREF="stock.php?action=detail&sg_code='.$r['sg_code'].'&year='.$p_year.'">'.
$r['sg_code']."</A></td>";
// name
$a_name=getFicheNameCode($p_cn,$r['sg_code']);
$name="";
if ( $a_name != null ) {
foreach ($a_name as $key=>$element) {
$name.=$element['av_text'].",";
}
}// if ( $a_name
$result.="<td> $name </td>";
// Debit (in)
$result.="<td>".$r['deb_sum']."</td>";
// Credit (out)
$result.="<td>".$r['cred_sum']."</td>";
$result.="<td>".$r['deb_sum']-$r['cred_sum']."</td>";
// diff
$diff=$r['deb_sum']-$r['cred_sum'];
$result.="<td>".$diff."</td>";
$result.="</tr>";
}
$result.="</table>";
$result.="</table>";
return $result;
}
/* function ViewDetailStock ($p_cn,$p_f_id,$p_year)
**************************************************
************************************************************
* Purpose : return all the stock movement
*
* parm :
@ -102,4 +115,41 @@ function ViewDetailStock($p_cn,$p_f_id,$p_year) {
}
/* function getFicheNameCode ($p_cn,$p_sg_code)
************************************************************
* Purpose : return an array of f_id and f_name
*
* parm :
* - p_cn database connection
* - stock_goods.sg_code
* gen :
* - none
* return:
* - array (f_id, f_label) or null if nothing is found
*/
function getFicheNameCode ($p_cn,$p_sg_code) {
// Sql stmt
$sql="select f_id,av_text
from stock_goods
join jnt_fic_att_value using (f_id )
join attr_value using (jft_id)
where
ad_id=".ATTR_DEF_NAME."
and sg_code='$p_sg_code'
and sg_code != null ";
// Execute
$Res=ExecSql($p_cn,$sql);
if ( ( $M=pg_NumRows($Res)) == 0 ) return null;
// Store in an array
for ( $i=0; $i<$M;$i++) {
$r=pg_fetch_array($Res,$i);
$a['f_id']=$r['f_id'];
$a['av_text']=$r['av_text'];
$result[$i]=$a;
}
return $result;
}

View file

@ -93,6 +93,8 @@ if ( $action == 'new' ) {
// if something goes wrong, correct it
if ( $r == null ) {
$submit='<INPUT TYPE="SUBMIT" NAME="add_item" VALUE="Ajout article">
<INPUT TYPE="SUBMIT" NAME="view_invoice" VALUE="Sauver">';
$r=FormAch($cn,$g_jrn,$g_user,$submit,$HTTP_POST_VARS,false, $nb_number);
}
echo '<div class="u_redcontent">';

View file

@ -90,6 +90,10 @@ if ( $action == 'new' ) {
// if something goes wrong correct it
if ( $r == null ) {
// submit button in the form
$submit='<INPUT TYPE="SUBMIT" NAME="add_item" VALUE="Ajout article">
<INPUT TYPE="SUBMIT" NAME="view_invoice" VALUE="Sauver">';
$r=FormFin($cn,$g_jrn,$g_user,$submit,$HTTP_POST_VARS,false, $nb_number);
}

View file

@ -219,7 +219,8 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null)
jrn_def_id,
jrn_def_name,
jrn_def_ech,
jrn_def_type
jrn_def_type,
jr_valid
from
jrn join jrn_def on jrn_def_id=jr_def_id
$p_where
@ -242,7 +243,8 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null)
jrn_def_id,
jrn_def_name,
jrn_def_ech,
jrn_def_type
jrn_def_type,
jr_valid
from
jrn join jrn_def on jrn_def_id=jr_def_id where jrn_def_id=$p_jrn";
$l_and=" and ";
@ -331,13 +333,14 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null)
}// if ( $a != null ) {
$r.="</TD>";
//$l=user_jrn.php?action=update&line=91
// TODO Add print
$r.="<TD>";
// cancel operation
$r.=sprintf('<input TYPE="BUTTON" VALUE="%s" onClick="cancelOperation(\'%s\',\'%s\')">',
"Annulation",$row['jr_grpt_id'],$l_sessid);
$r.="</TD>";
if ( $row['jr_valid'] == 't' ) {
// TODO Add print
$r.="<TD>";
// cancel operation
$r.=sprintf('<input TYPE="BUTTON" VALUE="%s" onClick="cancelOperation(\'%s\',\'%s\')">',
"Annulation",$row['jr_grpt_id'],$l_sessid);
$r.="</TD>";
}
// end row
$r.="</tr>";
@ -595,3 +598,31 @@ function UpdateComment ($p_cn,$p_jr_id,$p_comment) {
}
/* function isValid ($p_cn, $p_grpt_id
**************************************************
* Purpose : test if a jrn op is valid
*
* parm :
* - db connection
* - p_grpt_id
* gen :
* - none
* return:
* 1 is valid
* 0 is not valid
*/
function isValid ($p_cn,$p_grpt_id) {
$Res=ExecSql($p_cn,"select jr_valid from jrn where jr_grpt_id=$p_grpt_id");
if ( ( $M = pg_NumRows($Res)) == 0 ) return 0;
$a=pg_fetch_array($Res,0);
if ( $a['jr_valid'] == 't') return 1;
if ( $a['jr_valid'] == 'f') return 0;
echo_error ("Invalid result = ".$a['result']);
}