Fix 2398 : bug si melange de montants négatifs et positifs avec de la

TVA en autoliquidation
This commit is contained in:
sparkyx 2024-12-20 19:45:16 +01:00
parent c64f356cfa
commit 846171f4e1
5 changed files with 455 additions and 47 deletions

View file

@ -65,10 +65,88 @@ class Acc_Ledger_PurchaseTest extends TestCase
"p_currency_code"=>1
);
// create accounting for reversed VAT
// create accounting for reversed VAT with neg. amount
$g_connection->exec_sql("
INSERT INTO public.tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use) VALUES
('4119999','TVA Test UNIT','411','ACT','Y') on conflict do nothing");
/// @var $array1 = used for autoreverse with 2 VAT Codes
$this->array1=array (
'e_client' => 'FOURNI1',
'nb_item' => '10',
'p_jrn' => '3',
'jrn_note_input' => '',
'e_comm' => 'Documentation',
'e_date' => '30.01.2020',
'e_ech' => '',
'jrn_type' => 'ACH',
'e_pj' => 'ACH53',
'e_pj_suggest' => 'ACH53',
'p_currency_rate' => '1',
'p_currency_code' => '0',
'mt' => '1734717784.385',
'e_mp' => '0',
'e_march0' => 'DOCUME',
'e_march0_price' => '120',
'e_march0_tva_id' => '5',
'e_march0_tva_amount' => '0',
'e_quant0' => '1',
'e_march1' => 'DOCUME',
'e_march1_price' => '-10',
'e_march1_tva_id' => '3',
'e_march1_tva_amount' => '0',
'e_quant1' => '1',
'e_march2' => '',
'e_march2_price' => '',
'e_march2_tva_id' => '',
'e_march2_tva_amount' => '',
'e_quant2' => '1',
'e_march3' => '',
'e_march3_price' => '',
'e_march3_tva_id' => '',
'e_march3_tva_amount' => '',
'e_quant3' => '1',
'e_march4' => '',
'e_march4_price' => '',
'e_march4_tva_id' => '',
'e_march4_tva_amount' => '',
'e_quant4' => '1',
'e_march5' => '',
'e_march5_price' => '',
'e_march5_tva_id' => '',
'e_march5_tva_amount' => '',
'e_quant5' => '1',
'e_march6' => '',
'e_march6_price' => '',
'e_march6_tva_id' => '',
'e_march6_tva_amount' => '',
'e_quant6' => '1',
'e_march7' => '',
'e_march7_price' => '',
'e_march7_tva_id' => '',
'e_march7_tva_amount' => '',
'e_quant7' => '1',
'e_march8' => '',
'e_march8_price' => '',
'e_march8_tva_id' => '',
'e_march8_tva_amount' => '',
'e_quant8' => '1',
'e_march9' => '',
'e_march9_price' => '',
'e_march9_tva_id' => '',
'e_march9_tva_amount' => '',
'e_quant9' => '1',
'ac' => 'COMPTA/MENUACH/ACH',
'bon_comm' => '',
'other_info' => '',
'opd_name' => '',
'od_description' => '',
'reverse_date' => '',
'ext_label' => '',
'jr_optype' => 'NOR',
'action_gestion' => '',
'record' => 'Enregistrement',
);
}
@ -648,4 +726,97 @@ class Acc_Ledger_PurchaseTest extends TestCase
$this->clean_operation();
}
/**
* @testdox Reverse VAT4 :Use 2 different VAT Autoreverse mix negative and positive amounts
* @covers Acc_Ledger_Sale::insert
* @return void
*/
function testInsertReverseVAT4() {
global $g_connection;
$array=$this->array1;
$old_autoreverse=$g_connection->get_value("select tva_both_side from tva_rate where tva_id=3 ");
// set autoreverse to 1
$g_connection->get_value("update tva_rate set tva_both_side = 1 where tva_id=3 ");
// clean
$g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]);
$this->object->insert($array);
$accounting=new \Acc_Operation($g_connection);
$accounting->jr_id=$this->object->jr_id;
$aResult=$accounting->get_jrnx_detail();
$this->assertTrue(count($aResult)==7, 'Number of rows is '.count($aResult)."instead of 7");
foreach($aResult as $result) {
switch ($result['j_poste']) {
case '41142':
$this->assertEquals(25.20, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
case '6194':
if ( $result['debit']=='D')
$this->assertEquals(120, $result['j_montant'],"erreur account {$result['j_poste']}");
else
$this->assertEquals(10, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
case '4400005':
$this->assertEquals(110, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
}
}
// cancel change
$g_connection->get_value("update tva_rate set tva_both_side = $1 where tva_id=3 ",[$old_autoreverse]);
$g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]);
}
/**
* @testdox Reverse VAT5 :Use 2 same VAT Autoreverse mix negative and positive amounts
* @covers Acc_Ledger_Sale::insert
* @return void
*/
function testInsertReverseVAT5() {
global $g_connection;
$array=$this->array1;
$array['e_march1_tva_id']=5;
// clean
$g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]);
$this->object->insert($array);
$accounting=new \Acc_Operation($g_connection);
$accounting->jr_id=$this->object->jr_id;
$aResult=$accounting->get_jrnx_detail();
$this->assertTrue(count($aResult)==7, 'Number of rows is '.count($aResult)."instead of 7");
foreach($aResult as $result) {
switch ($result['j_poste']) {
case '41142':
if ( $result['debit']=='D')
$this->assertEquals(25.20, $result['j_montant'],"erreur account {$result['j_poste']}");
else
$this->assertEquals(2.1, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
case '6194':
if ( $result['debit']=='D')
$this->assertEquals(120, $result['j_montant'],"erreur account {$result['j_poste']}");
else
$this->assertEquals(10, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
case '4400005':
$this->assertEquals(110, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
}
}
// cancel change
$g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]);
}
}

View file

@ -74,8 +74,41 @@ class Acc_Ledger_SaleTest extends TestCase
$g_connection->exec_sql("
INSERT INTO public.tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use) VALUES
('4119999','TVA Test UNIT','411','ACT','Y') on conflict do nothing");
// create accounting for reversed VAT with neg. amount
$this->array1=array( 'e_client' => 'CLIENT1',
'nb_item' => '2',
'p_jrn' => '2',
'jrn_note_input' => '',
'mt' => '1734720448.0036',
'p_currency_rate' => '1',
'p_currency_code' => '0',
'e_comm' => '',
'e_date' => '27.06.2020',
'e_ech' => '',
'e_pj' => 'VEN41',
'e_pj_suggest' => 'VEN41',
'e_mp' => '0',
'jrn_type' => 'VEN',
'e_march0' => 'DEPLAC',
'e_march0_price' => '20',
'e_march0_tva_id' => '5',
'e_march0_tva_amount' => '0',
'e_quant0' => '1',
'e_march1' => 'DEPLAC',
'e_march1_price' => '-5',
'e_march1_tva_id' => '5',
'e_march1_tva_amount' => '0',
'e_quant1' => '1',
'ac' => 'COMPTA/VENMENU/VEN',
'bon_comm' => '',
'other_info' => '',
'opd_name' => '',
'od_description' => '',
'reverse_date' => '',
'ext_label' => '',
'jr_optype' => 'NOR',
'action_gestion' => '',
'record' => 'Enregistrement');
}
/**
@ -503,5 +536,100 @@ class Acc_Ledger_SaleTest extends TestCase
$ret=$this->object->get_detail_sale(92,103,'unpaid');
$this->assertEquals(5,Database::num_row($ret),'only unpaid operations');
}
/**
* @testdox Reverse VAT4 :Use 2 different VAT Autoreverse mix negative and positive amounts
* @covers Acc_Ledger_Sale::insert
* @return void
*/
function testInsertReverseVAT4() {
global $g_connection;
$array=$this->array1;
$old_autoreverse=$g_connection->get_value("select tva_both_side from tva_rate where tva_id=3 ");
// set autoreverse to 1
$g_connection->get_value("update tva_rate set tva_both_side = 1 where tva_id=3 ");
$array['e_march1_tva_id']=3;
// clean
$g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]);
$this->object->insert($array);
$accounting=new \Acc_Operation($g_connection);
$accounting->jr_id=$this->object->jr_id;
$aResult=$accounting->get_jrnx_detail();
$this->assertTrue(count($aResult)==7, 'Number of rows is '.count($aResult)."instead of 7");
foreach($aResult as $result) {
switch ($result['j_poste']) {
case '41142':
if ( $result['debit']=='D')
$this->assertEquals(4.20, $result['j_montant'],"erreur account {$result['j_poste']}");
else
$this->assertEquals(1.05, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
case '7000005':
if ( $result['debit']=='D')
$this->assertEquals(5, $result['j_montant'],"erreur account {$result['j_poste']}");
else
$this->assertEquals(20, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
case '4000005':
$this->assertEquals(15, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
}
}
// cancel change
$g_connection->get_value("update tva_rate set tva_both_side = $1 where tva_id=3 ",[$old_autoreverse]);
$g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]);
}
/**
* @testdox Reverse VAT5 :Use 2 same VAT Autoreverse mix negative and positive amounts
* @covers Acc_Ledger_Sale::insert
* @return void
*/
function testInsertReverseVAT5() {
global $g_connection;
$array=$this->array1;
$array['e_march1_tva_id']=5;
// clean
$g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]);
$this->object->insert($array);
$accounting=new \Acc_Operation($g_connection);
$accounting->jr_id=$this->object->jr_id;
$aResult=$accounting->get_jrnx_detail();
$this->assertTrue(count($aResult)==7, 'Number of rows is '.count($aResult)."instead of 7");
foreach($aResult as $result) {
switch ($result['j_poste']) {
case '41142':
if ( $result['debit']=='D')
$this->assertEquals(4.20, $result['j_montant'],"erreur account {$result['j_poste']}");
else
$this->assertEquals(1.05, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
case '7000005':
if ( $result['debit']=='D')
$this->assertEquals(5, $result['j_montant'],"erreur account {$result['j_poste']}");
else
$this->assertEquals(20, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
case '4000005':
$this->assertEquals(15, $result['j_montant'],"erreur account {$result['j_poste']}");
break;
}
}
// cancel change
$g_connection->exec_sql("delete from jrn where jr_mt=$1",[1734717784.385]);
}
}