Task #2411: In order to issue invoice with a full description of the task through FOLLOW

This commit is contained in:
sparkyx 2025-03-13 12:48:55 +01:00
parent 3d4db2ee28
commit 21edd301e7
6 changed files with 93 additions and 9 deletions

View file

@ -3249,7 +3249,16 @@ class Acc_Ledger extends jrn_def_sql
return $array;
}
function convert_from_follow($p_ag_id)
/**
* @brief convert operations from FOLLOWUP into a SALE , FEENOTE
* or PURCHASE operation into a suitable array
* @param $p_ag_id int PK of ACTION_GESTION
* @param $copy_description int 0 the description of the followup is not copied
* in the note , 1 is copied
* @return array|void|null
* @throws Exception
*/
function convert_from_follow($p_ag_id,$copy_description=0)
{
global $g_user;
if (isNumber($p_ag_id)==0)
@ -3290,6 +3299,13 @@ class Acc_Ledger extends jrn_def_sql
$array['e_march'.$i.'_tva_amount']=$a_item[$i]['ad_tva_amount'];
$array['e_quant'.$i]=$a_item[$i]['ad_quant'];
}
if ( $copy_description == 1) {
$acomment=$this->db->get_array("SELECT agc_id, ag_id, to_char(agc_date,'DD.MM.YYYY HH24:MI') as str_agc_date, agc_comment, agc_comment_raw,tech_user
FROM action_gestion_comment where ag_id=$1 order by agc_id", array($p_ag_id)
);
if (count ($acomment) > 0)
$array['jrn_note_input']=$acomment[0]['agc_comment'];
}
return $array;
}

View file

@ -252,7 +252,8 @@ try
else if (isset($_GET['create_feenote']))
{
$action_id=$http->get('ag_id',"number");
$array=$Ledger->convert_from_follow($action_id);
$cp=$http->get('cp','number',0);
$array=$Ledger->convert_from_follow($action_id,$cp);
echo HtmlInput::hidden("ledger_type", "VEN");
echo HtmlInput::hidden("ac",$http->get('ac'));
echo HtmlInput::hidden("sa", "p");

View file

@ -267,7 +267,8 @@ try
else if (isset($_GET['create_invoice']))
{
$action_id=$http->get('ag_id',"number");
$array=$Ledger->convert_from_follow($action_id);
$cp=$http->get('cp','number',0);
$array=$Ledger->convert_from_follow($action_id,$cp);
echo HtmlInput::hidden("ledger_type", "VEN");
echo HtmlInput::hidden("ac", $http->get('ac'));
echo HtmlInput::hidden("sa", "p");

View file

@ -248,8 +248,8 @@ class HtmlInput
/*!\brief create a button with a ref
* \param $p_label the text
* \param $p_value the location of the window,
* \param $p_name the id of the span
* \param $p_javascript javascript for this button
* \param $p_name the id of the span (button will be "btn".$p_name
* \param $p_javascript javascript for this button, needed to add the event : onclick,...
* \return string with htmlcode
*/
@ -259,8 +259,8 @@ class HtmlInput
$href="";
if ($p_value!="")
$href=sprintf(' href ="%s" ', $p_value);
$r=sprintf('<span id="%s" > <A class="'.$p_class.'" style="display:inline-block;" %s %s >%s</A></span>',
$p_name, $href, $p_javascript, $p_label);
$r=sprintf('<span id="%s" > <A class="'.$p_class.'" id="btn%s" style="display:inline-block;" %s %s >%s</A></span>',
$p_name, $p_name,$href, $p_javascript, $p_label);
return $r;
}
/**

View file

@ -200,8 +200,21 @@ $menu=new Default_Menu();
if (Document_Option::is_enable_make_invoice($p_follow_up->dt_id)):
?>
<div id="follow_up_detail_invoice" class="col m-3" style="position:static">
<div> <input type="checkbox" id="invoice_cp_note" value="0"> Cocher pour copier la description dans la <b>note de la vente</b></div>
<script>
(function () {
$('invoice_cp_note').addEventListener("change", function () {
let cp= $('btncreate_invoice').attributes['href'].nodeValue;
if ( $('invoice_cp_note').checked) {
$('btncreate_invoice').attributes['href'].nodeValue= cp.replace('cp=0','cp=1')
} else {
$('btncreate_invoice').attributes['href'].nodeValue= cp.replace('cp=1','cp=0')
}
});
})();
</script>
<?php
$query=http_build_query(array('gDossier'=>Dossier::id(), 'ag_id'=>$p_follow_up->ag_id, 'create_invoice'=>1, 'ac'=>$menu->get('code_invoice')));
$query=http_build_query(array('gDossier'=>Dossier::id(), 'ag_id'=>$p_follow_up->ag_id, 'create_invoice'=>1,'cp'=>0, 'ac'=>$menu->get('code_invoice')));
echo HtmlInput::button_anchor(_("Transformer en Facture de Vente"), "do.php?".$query, "create_invoice",
' target="_blank" ', "button");
?>
@ -214,8 +227,21 @@ $menu=new Default_Menu();
if (Document_Option::is_enable_make_feenote($p_follow_up->dt_id)):
?>
<div id="follow_up_detail_feenote" class="col m-3" style="position:static">
<div> <input type="checkbox" id="feenote_cp_note" value="0"> Cocher pour copier la description dans la <b>note de l'achat ou note de frais</b></div>
<script>
(function () {
$('feenote_cp_note').addEventListener("change", function () {
let cp= $('btncreate_feenote').attributes['href'].nodeValue;
if ( $('feenote_cp_note').checked) {
$('btncreate_feenote').attributes['href'].nodeValue= cp.replace('cp=0','cp=1')
} else {
$('btncreate_feenote').attributes['href'].nodeValue= cp.replace('cp=1','cp=0')
}
});
})();
</script>
<?php
$query=http_build_query(array('gDossier'=>Dossier::id(), 'ag_id'=>$p_follow_up->ag_id, 'create_feenote'=>1, 'ac'=>$menu->get('code_feenote')));
$query=http_build_query(array('cp'=>0,'gDossier'=>Dossier::id(), 'ag_id'=>$p_follow_up->ag_id, 'create_feenote'=>1, 'ac'=>$menu->get('code_feenote')));
echo HtmlInput::button_anchor(_("Transformer en Note de frais ou Facture Achat"), "do.php?".$query, "create_feenote",
' target="_blank" ', "button");
?>

View file

@ -1064,4 +1064,44 @@ class Acc_LedgerTest extends TestCase
$this->assertEquals($this->object->is_enable(),1);
}
/**
* @testdox convert from FollowUp : Description is asked
* @covers Acc_Ledger::convert_from_follow
* @return void
* @throws Exception
*/
public function testConvert_from_follow_copy1()
{
$action_gestion_id=1;
$result=$this->object-> convert_from_follow($action_gestion_id,1);
$this->assertTrue($result['jrn_note_input']=='Test',print_r($result,true));
}
/**
* @testdox convert from FollowUp : Description is not asked
* @covers Acc_Ledger::convert_from_follow
* @return void
* @throws Exception
*/
public function testConvert_from_follow_copy2()
{
$action_gestion_id=1;
$result=$this->object-> convert_from_follow($action_gestion_id,0);
$this->assertTrue(! isset ($result['jrn_note_input']),print_r($result,true));
}
/**
* @testdox convert from FollowUp : Description is asked and there is no description available
* @covers Acc_Ledger::convert_from_follow
* @return void
* @throws Exception
*/
public function testConvert_from_follow_copy3()
{
$action_gestion_id=15;
$result=$this->object-> convert_from_follow($action_gestion_id,1);
$this->assertTrue(! isset ($result['jrn_note_input']),print_r($result,true));
}
}