0000392: Cocontractant : TVA au débit ET crédit
This commit is contained in:
parent
a1b76f6197
commit
f1d201f1bf
5 changed files with 156 additions and 88 deletions
|
|
@ -384,7 +384,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
|
|||
$acc_amount->amount_vat= ${'e_march'.$i.'_tva_amount'};
|
||||
|
||||
}
|
||||
$tot_tva+=$acc_amount->amount_vat;
|
||||
if ($oTva->get_parameter("both_side")==0) $tot_tva=bcadd($tot_tva,$acc_amount->amount_vat);
|
||||
}
|
||||
|
||||
$acc_operation=new Acc_Operation($this->db);
|
||||
|
|
@ -667,6 +667,20 @@ class Acc_Ledger_Purchase extends Acc_Ledger
|
|||
$acc_operation->periode=$tperiode;
|
||||
if ( $value > 0 ) $tot_debit=bcadd($tot_debit,$value);
|
||||
$acc_operation->insert_jrnx();
|
||||
// if TVA is on both side, we deduce it immediately
|
||||
if ( $oTva->get_parameter("both_side")==1)
|
||||
{
|
||||
$poste_vat=$oTva->get_side('c');
|
||||
$cust_amount=bcadd($tot_amount,$tot_tva);
|
||||
$acc_operation=new Acc_Operation($this->db);
|
||||
$acc_operation->date=$e_date;
|
||||
$acc_operation->poste=$poste_vat;
|
||||
$acc_operation->amount=$value;
|
||||
$acc_operation->grpt=$seq;
|
||||
$acc_operation->jrn=$p_jrn;
|
||||
$acc_operation->type='c';
|
||||
$acc_operation->periode=$tperiode;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ class Acc_Ledger_Sold extends Acc_Ledger
|
|||
$tva[$idx_tva]+=$tva_item;
|
||||
else
|
||||
$tva[$idx_tva]=$tva_item;
|
||||
$tot_tva=round(bcadd($tva_item,$tot_tva),2);
|
||||
if ($oTva->get_parameter("both_side")==0) $tot_tva=round(bcadd($tva_item,$tot_tva),2);
|
||||
}
|
||||
|
||||
/* Save the stock */
|
||||
|
|
@ -429,6 +429,21 @@ class Acc_Ledger_Sold extends Acc_Ledger
|
|||
$acc_operation->periode=$tperiode;
|
||||
if ($value < 0 ) $tot_debit=bcadd($tot_debit,abs($value));
|
||||
$acc_operation->insert_jrnx();
|
||||
|
||||
// if TVA is on both side, we deduce it immediately
|
||||
if ( $oTva->get_parameter("both_side")==1)
|
||||
{
|
||||
$poste_vat=$oTva->get_side('d');
|
||||
$cust_amount=bcadd($tot_amount,$tot_tva);
|
||||
$acc_operation=new Acc_Operation($this->db);
|
||||
$acc_operation->date=$e_date;
|
||||
$acc_operation->poste=$poste_vat;
|
||||
$acc_operation->amount=$value;
|
||||
$acc_operation->grpt=$seq;
|
||||
$acc_operation->jrn=$p_jrn;
|
||||
$acc_operation->type='d';
|
||||
$acc_operation->periode=$tperiode;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ class Acc_Tva
|
|||
"label"=>"tva_label",
|
||||
"rate"=>"tva_rate",
|
||||
"comment"=>"tva_comment",
|
||||
"account"=>"tva_poste");
|
||||
"account"=>"tva_poste",
|
||||
"both_side"=>'tva_both_side');
|
||||
|
||||
function __construct ($p_init,$p_tva_id=0)
|
||||
{
|
||||
|
|
@ -94,14 +95,15 @@ class Acc_Tva
|
|||
public function insert()
|
||||
{
|
||||
if ( $this->verify() != 0 ) return;
|
||||
$sql="select tva_insert($1,$2,$3,$4)";
|
||||
$sql="select tva_insert($1,$2,$3,$4,$5)";
|
||||
|
||||
$res=$this->cn->exec_sql(
|
||||
$sql,
|
||||
array($this->tva_label,
|
||||
$this->tva_rate,
|
||||
$this->tva_comment,
|
||||
$this->tva_poste)
|
||||
$this->tva_poste,
|
||||
$this->tva_both_side)
|
||||
);
|
||||
$this->tva_id=$this->cn->get_current_seq('s_tva');
|
||||
$err=Database::fetch_result($res);
|
||||
|
|
@ -110,14 +112,15 @@ class Acc_Tva
|
|||
public function update()
|
||||
{
|
||||
if ( $this->verify() != 0 ) return;
|
||||
$sql="update tva_rate set tva_label=$1,tva_rate=$2,tva_comment=$3,tva_poste=$4 ".
|
||||
" where tva_id = $5";
|
||||
$sql="update tva_rate set tva_label=$1,tva_rate=$2,tva_comment=$3,tva_poste=$4,tva_both_side=$5 ".
|
||||
" where tva_id = $6";
|
||||
$res=$this->cn->exec_sql(
|
||||
$sql,
|
||||
array($this->tva_label,
|
||||
$this->tva_rate,
|
||||
$this->tva_comment,
|
||||
$this->tva_poste,
|
||||
$this->tva_both_side,
|
||||
$this->tva_id)
|
||||
);
|
||||
|
||||
|
|
@ -129,7 +132,7 @@ class Acc_Tva
|
|||
*/
|
||||
public function load()
|
||||
{
|
||||
$sql="select tva_label,tva_rate, tva_comment,tva_poste from tva_rate where tva_id=$1";
|
||||
$sql="select tva_label,tva_rate, tva_comment,tva_poste,tva_both_side from tva_rate where tva_id=$1";
|
||||
$res=$this->cn->exec_sql(
|
||||
$sql,
|
||||
array($this->tva_id)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ if (isset($_POST['confirm_rm']))
|
|||
echo '<p class="notice">Vous ne pouvez pas effacer tous taux' .
|
||||
' Si votre société n\'utilise pas la TVA, changer dans le menu société</p>';
|
||||
}
|
||||
$both=(isset($_REQUEST['both']))?1:0;
|
||||
//-----------------------------------------------------
|
||||
// Record Change
|
||||
if (isset($_POST['confirm_mod'])
|
||||
|
|
@ -54,23 +55,21 @@ if (isset($_POST['confirm_mod'])
|
|||
{
|
||||
if (isset($_POST['confirm_add']))
|
||||
{
|
||||
$sql = "select tva_insert($1,$2,$3,$4)";
|
||||
$sql = "select tva_insert($1,$2,$3,$4,$5)";
|
||||
|
||||
$res = $cn->exec_sql(
|
||||
$sql, array($tva_label,
|
||||
$tva_rate,
|
||||
$tva_comment,
|
||||
$tva_poste)
|
||||
$tva_poste,
|
||||
$both)
|
||||
);
|
||||
$err = Database::fetch_result($res);
|
||||
}
|
||||
if (isset($_POST['confirm_mod']))
|
||||
{
|
||||
$Res = $cn->exec_sql(
|
||||
"select tva_modify($tva_id,'$tva_label',
|
||||
'$tva_rate','$tva_comment','$tva_poste')");
|
||||
$Res = $cn->exec_sql(
|
||||
"select tva_modify($1,$2,$3,$4,$5)", array($tva_id, $tva_label, $tva_rate, $tva_comment, $tva_poste)
|
||||
"select tva_modify($1,$2,$3,$4,$5,$6)", array($tva_id, $tva_label, $tva_rate, $tva_comment, $tva_poste,$both)
|
||||
);
|
||||
$err = Database::fetch_result($Res);
|
||||
}
|
||||
|
|
@ -96,7 +95,7 @@ if ($own->MY_TVA_USE == 'N')
|
|||
}
|
||||
//-----------------------------------------------------
|
||||
// Display
|
||||
$sql = "select tva_id,tva_label,tva_rate,tva_comment,tva_poste from tva_rate order by tva_label";
|
||||
$sql = "select tva_id,tva_label,tva_rate,tva_comment,tva_poste,tva_both_side from tva_rate order by tva_label";
|
||||
$Res = $cn->exec_sql($sql);
|
||||
?>
|
||||
<TABLE>
|
||||
|
|
@ -105,6 +104,7 @@ $Res = $cn->exec_sql($sql);
|
|||
<th>Taux</th>
|
||||
<th>Commentaire</th>
|
||||
<th>Poste</th>
|
||||
<th>Utilisé en même temps au crédit et au débit</th>
|
||||
</tr>
|
||||
<?php
|
||||
$val = Database::fetch_all($Res);
|
||||
|
|
@ -116,7 +116,8 @@ foreach ($val as $row)
|
|||
'tva_label' => $row['tva_label'],
|
||||
'tva_rate' => $row['tva_rate'],
|
||||
'tva_comment' => $row['tva_comment'],
|
||||
'tva_poste' => $row['tva_poste']
|
||||
'tva_poste' => $row['tva_poste'],
|
||||
'tva_both_side' => $row['tva_both_side']
|
||||
);
|
||||
|
||||
echo "<TR>";
|
||||
|
|
@ -141,6 +142,11 @@ foreach ($val as $row)
|
|||
echo $row['tva_poste'];
|
||||
echo "</TD>";
|
||||
|
||||
echo "<TD>";
|
||||
$str_msg=( $row['tva_both_side']==1)?'Employé au crédit et débit':'normal' ;
|
||||
echo $str_msg;
|
||||
echo "</TD>";
|
||||
|
||||
echo "<TD>";
|
||||
echo HtmlInput::submit("rm", "Efface");
|
||||
echo HtmlInput::submit("mod", "Modifie");
|
||||
|
|
@ -194,12 +200,14 @@ if (isset($_REQUEST['rm']))
|
|||
<th>Taux</th>
|
||||
<th>Commentaire</th>
|
||||
<th>Poste</th>
|
||||
<th>Double côté</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> <?php echo $tva_array[$index]['tva_label'];?></td>
|
||||
<td> <?php echo $tva_array[$index]['tva_rate'];?></td>
|
||||
<td> <?php echo $tva_array[$index]['tva_comment'];?></td>
|
||||
<td> <?php echo $tva_array[$index]['tva_poste'];?></td>
|
||||
<td> <?php echo $tva_array[$index]['tva_both_side'];?></td>
|
||||
</Tr>
|
||||
</table>
|
||||
<?php
|
||||
|
|
@ -248,6 +256,14 @@ if (isset($_REQUEST['rm']))
|
|||
echo $w->input('tva_poste', '')
|
||||
?></td>
|
||||
</Tr>
|
||||
<tr>
|
||||
<td align="right">Utilisé au débit et au crédit afin d'annuler cette tva </td>
|
||||
<td> <?php
|
||||
$w = new ICheckBox("both", 1);
|
||||
$w->size = 20;
|
||||
echo $w->input('both', '')
|
||||
?></td>
|
||||
</Tr>
|
||||
</table>
|
||||
<input type="submit" class="button" value="Confirme" name="confirm_add">
|
||||
<input type="submit" class="button" value="Cancel" name="no">
|
||||
|
|
@ -302,6 +318,15 @@ if (isset($_REQUEST['mod']))
|
|||
echo $w->input('tva_poste', $tva_array[$index]['tva_poste'])
|
||||
?></td>
|
||||
</Tr>
|
||||
<tr>
|
||||
<td align="right">Utilisé au débit et au crédit afin d'annuler cette tva </td>
|
||||
<td> <?php
|
||||
$w = new ICheckBox("both",$tva_array[$index]['tva_both_side'] );
|
||||
$w->selected=$tva_array[$index]['tva_both_side'];
|
||||
$w->size = 20;
|
||||
echo $w->input('both', '')
|
||||
?></td>
|
||||
</Tr>
|
||||
</table>
|
||||
<input type="submit" class="button" value="Confirme" name="confirm_mod">
|
||||
<input type="submit" class="button" value="Cancel" name="no">
|
||||
|
|
|
|||
155
sql/tva.sql
155
sql/tva.sql
|
|
@ -1,74 +1,85 @@
|
|||
alter table tva_rate add tva_both_side integer ;
|
||||
alter table tva_rate alter tva_both_side set default 0;
|
||||
update tva_rate set tva_both_side=0;drop FUNCTION comptaproc.tva_modify(integer, text, numeric, text, text);
|
||||
|
||||
CREATE OR REPLACE FUNCTION comptaproc.tva_modify(integer, text, numeric, text, text,integer)
|
||||
RETURNS integer
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare
|
||||
p_tva_id alias for $1;
|
||||
p_tva_label alias for $2;
|
||||
p_tva_rate alias for $3;
|
||||
p_tva_comment alias for $4;
|
||||
p_tva_poste alias for $5;
|
||||
p_tva_both_side alias for $6;
|
||||
debit text;
|
||||
credit text;
|
||||
nCount integer;
|
||||
begin
|
||||
if length(trim(p_tva_label)) = 0 then
|
||||
return 3;
|
||||
end if;
|
||||
|
||||
if length(trim(p_tva_poste)) != 0 then
|
||||
if position (',' in p_tva_poste) = 0 then return 4; end if;
|
||||
debit = split_part(p_tva_poste,',',1);
|
||||
credit = split_part(p_tva_poste,',',2);
|
||||
select count(*) into nCount from tmp_pcmn where pcm_val=debit::account_type;
|
||||
if nCount = 0 then return 4; end if;
|
||||
select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type;
|
||||
if nCount = 0 then return 4; end if;
|
||||
|
||||
end if;
|
||||
update tva_rate set tva_label=p_tva_label,tva_rate=p_tva_rate,tva_comment=p_tva_comment,tva_poste=p_tva_poste,tva_both_side=p_tva_both_side
|
||||
where tva_id=p_tva_id;
|
||||
return 0;
|
||||
end;
|
||||
$function$
|
||||
drop FUNCTION comptaproc.tva_insert(text, numeric, text, text);
|
||||
CREATE OR REPLACE FUNCTION comptaproc.tva_insert(text, numeric, text, text,integer)
|
||||
RETURNS integer
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare
|
||||
l_tva_id integer;
|
||||
p_tva_label alias for $1;
|
||||
p_tva_rate alias for $2;
|
||||
p_tva_comment alias for $3;
|
||||
p_tva_poste alias for $4;
|
||||
p_tva_both_side alias for $5;
|
||||
debit text;
|
||||
credit text;
|
||||
nCount integer;
|
||||
begin
|
||||
if length(trim(p_tva_label)) = 0 then
|
||||
return 3;
|
||||
end if;
|
||||
|
||||
if length(trim(p_tva_poste)) != 0 then
|
||||
if position (',' in p_tva_poste) = 0 then return 4; end if;
|
||||
debit = split_part(p_tva_poste,',',1);
|
||||
credit = split_part(p_tva_poste,',',2);
|
||||
select count(*) into nCount from tmp_pcmn where pcm_val=debit::account_type;
|
||||
if nCount = 0 then return 4; end if;
|
||||
select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type;
|
||||
if nCount = 0 then return 4; end if;
|
||||
|
||||
end if;
|
||||
select into l_tva_id nextval('s_tva') ;
|
||||
insert into tva_rate(tva_id,tva_label,tva_rate,tva_comment,tva_poste,tva_both_side)
|
||||
values (l_tva_id,p_tva_label,p_tva_rate,p_tva_comment,p_tva_poste,p_tva_both_side);
|
||||
return 0;
|
||||
end;
|
||||
$function$
|
||||
update tva_rate set tva_both_side=0;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- TVA MODIFY
|
||||
----------------------------------------------------------------------
|
||||
drop FUNCTION comptaproc.tva_modify(integer, text, numeric, text, text);
|
||||
|
||||
CREATE OR REPLACE FUNCTION comptaproc.tva_modify(integer, text, numeric, text, text,integer)
|
||||
RETURNS integer
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare
|
||||
p_tva_id alias for $1;
|
||||
p_tva_label alias for $2;
|
||||
p_tva_rate alias for $3;
|
||||
p_tva_comment alias for $4;
|
||||
p_tva_poste alias for $5;
|
||||
p_tva_both_side alias for $6;
|
||||
debit text;
|
||||
credit text;
|
||||
nCount integer;
|
||||
begin
|
||||
if length(trim(p_tva_label)) = 0 then
|
||||
return 3;
|
||||
end if;
|
||||
|
||||
if length(trim(p_tva_poste)) != 0 then
|
||||
if position (',' in p_tva_poste) = 0 then return 4; end if;
|
||||
debit = split_part(p_tva_poste,',',1);
|
||||
credit = split_part(p_tva_poste,',',2);
|
||||
select count(*) into nCount from tmp_pcmn where pcm_val=debit::account_type;
|
||||
if nCount = 0 then return 4; end if;
|
||||
select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type;
|
||||
if nCount = 0 then return 4; end if;
|
||||
|
||||
end if;
|
||||
update tva_rate set tva_label=p_tva_label,tva_rate=p_tva_rate,tva_comment=p_tva_comment,tva_poste=p_tva_poste,tva_both_side=p_tva_both_side
|
||||
where tva_id=p_tva_id;
|
||||
return 0;
|
||||
end;
|
||||
$function$
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- TVA INSERT
|
||||
----------------------------------------------------------------------
|
||||
|
||||
drop FUNCTION comptaproc.tva_insert(text, numeric, text, text);
|
||||
|
||||
CREATE OR REPLACE FUNCTION comptaproc.tva_insert(text, numeric, text, text,integer)
|
||||
RETURNS integer
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare
|
||||
l_tva_id integer;
|
||||
p_tva_label alias for $1;
|
||||
p_tva_rate alias for $2;
|
||||
p_tva_comment alias for $3;
|
||||
p_tva_poste alias for $4;
|
||||
p_tva_both_side alias for $5;
|
||||
debit text;
|
||||
credit text;
|
||||
nCount integer;
|
||||
begin
|
||||
if length(trim(p_tva_label)) = 0 then
|
||||
return 3;
|
||||
end if;
|
||||
|
||||
if length(trim(p_tva_poste)) != 0 then
|
||||
if position (',' in p_tva_poste) = 0 then return 4; end if;
|
||||
debit = split_part(p_tva_poste,',',1);
|
||||
credit = split_part(p_tva_poste,',',2);
|
||||
select count(*) into nCount from tmp_pcmn where pcm_val=debit::account_type;
|
||||
if nCount = 0 then return 4; end if;
|
||||
select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type;
|
||||
if nCount = 0 then return 4; end if;
|
||||
|
||||
end if;
|
||||
select into l_tva_id nextval('s_tva') ;
|
||||
insert into tva_rate(tva_id,tva_label,tva_rate,tva_comment,tva_poste,tva_both_side)
|
||||
values (l_tva_id,p_tva_label,p_tva_rate,p_tva_comment,p_tva_poste,p_tva_both_side);
|
||||
return 0;
|
||||
end;
|
||||
$function$
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue