Task #0001904: Previsions et budgets

Ajout montant initial and estimation cumulée pour avoir évolution passif/actif
This commit is contained in:
sparkyx 2021-03-28 15:21:47 +02:00
parent e9643d4a4f
commit b00558ee26
6 changed files with 101 additions and 54 deletions

View file

@ -220,7 +220,8 @@ EOF;
for ($j = 0; $j < count($aCat); $j++) {
// Item of the category, estimation for a specific month
$aItem[$j] = $this->cn->get_array('select fi_card,fi_account,fi_text,fi_amount,fi_debit
$aItem[$j] = $this->cn->get_array('select fi_card,fi_account,fi_text,fi_amount,fi_debit ,
fi_amount_initial
from forecast_item where fc_id=$1 and fi_pid=0 order by fi_order ',
array($aCat[$j]['fc_id']));

View file

@ -187,6 +187,8 @@ class Forecast_Item_MTable extends Manage_Table_SQL
$object_sql->setp("fi_amount",$http->post('fi_amount',"number"));
$object_sql->setp("fi_pid",$http->post('fi_pid',"number"));
$object_sql->setp("fi_debit",$http->post('fi_debit'));
$object_sql->setp("fi_amount_initial",$http->post("fi_amount_initial","number"));
$card=trim($http->post("fi_card"));
if ( $card !="") {
$f_id=$object_sql->cn->get_value("select f_id from fiche_detail where ad_value=upper($1) and ad_id=23",[$card]);

View file

@ -18,9 +18,8 @@
* along with NOALYSS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once NOALYSS_INCLUDE . '/lib/noalyss_sql.class.php';
require_once NOALYSS_INCLUDE . '/class/database.class.php';
require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
require_once NOALYSS_INCLUDE.'/class/database.class.php';
/**
* class_forecast_item_sql.php
@ -31,47 +30,48 @@ require_once NOALYSS_INCLUDE . '/class/database.class.php';
class Forecast_Item_SQL extends Noalyss_SQL
{
function __construct(DatabaseCore $p_cn, $p_id = -1)
function __construct(DatabaseCore $p_cn, $p_id=-1)
{
$this->table = "public.forecast_item";
$this->primary_key = "fi_id";
$this->table="public.forecast_item";
$this->primary_key="fi_id";
/*
* List of columns
*/
$this->name = array(
"fi_id" => "fi_id"
, "fi_text" => "fi_text"
, "fi_account" => "fi_account"
, "fi_card" => "fi_card"
, "fi_order" => "fi_order"
, "fc_id" => "fc_id"
, "fi_amount" => "fi_amount"
, "fi_debit" => "fi_debit"
, "fi_pid" => "fi_pid"
$this->name=array(
"fi_id"=>"fi_id"
, "fi_text"=>"fi_text"
, "fi_account"=>"fi_account"
, "fi_card"=>"fi_card"
, "fi_order"=>"fi_order"
, "fc_id"=>"fc_id"
, "fi_amount"=>"fi_amount"
, "fi_debit"=>"fi_debit"
, "fi_pid"=>"fi_pid"
, "fi_amount_initial"=>"fi_amount_initial"
);
/*
* Type of columns
*/
$this->type = array(
"fi_id" => "numeric"
, "fi_text" => "text"
, "fi_account" => "text"
, "fi_card" => "numeric"
, "fi_order" => "numeric"
, "fc_id" => "numeric"
, "fi_amount" => "numeric"
, "fi_debit" => "char"
, "fi_pid" => "numeric"
$this->type=array(
"fi_id"=>"numeric"
, "fi_text"=>"text"
, "fi_account"=>"text"
, "fi_card"=>"numeric"
, "fi_order"=>"numeric"
, "fc_id"=>"numeric"
, "fi_amount"=>"numeric"
, "fi_debit"=>"char"
, "fi_pid"=>"numeric"
, "fi_amount_initial"=>"numeric"
);
$this->default = array(
"fi_id" => "auto"
$this->default=array(
"fi_id"=>"auto"
);
$this->date_format = "DD.MM.YYYY";
$this->date_format="DD.MM.YYYY";
parent::__construct($p_cn, $p_id);
}
}
}

View file

@ -1,5 +1,7 @@
begin ;
alter table forecast_cat rename to forecast_category;
alter table forecast_category alter f_id set not null;
alter table forecast_item add fi_amount_initial numeric(20,4);
alter table forecast_item alter fi_amount_initial set default 0;
insert into version (val,v_description) values (154,'Rewriting of FORECAST');
commit;

View file

@ -7,7 +7,7 @@ Période du <?php echo $str_start?> à <?php echo $str_end;?>
<?php if (count($aItem[$i])==0) continue;?>
<fieldset>
<legend>
<?php echo $aCat[$i]['fc_desc'];$tot_cat_estm=0;$tot_cat_real=0;$tot_cum_real=0;?>
<?php echo $aCat[$i]['fc_desc'];$tot_cat_estm=0;$tot_cat_real=0;$tot_cum_real=0;$tot_cum_estm=[];?>
</legend>
<?php for ($e=0;$e<count($aItem[$i]);$e++):?>
@ -39,9 +39,14 @@ Période du <?php echo $str_start?> à <?php echo $str_end;?>
<td style="text-align:right;">
<?php
$amount=$aItem[$i][$e]['fi_amount'];
$amount_initial=0;
// -- if first periode , get the initial amou
if ( $h == 0 ) {
$amount_initial=$aItem[$i][$e]['fi_amount_initial'];
}
if (count($aPerMonth[$i]) != 0 ){
for ($x=0;$x<count($aPerMonth[$i]);$x++) {
if (DEBUGNOALYSS>2) {
if (DEBUGNOALYSS>1) {
printf (" \$aItem [$i] [$e] = %s",$aItem[$i][$e]['fi_amount']);
echo p("\$aPeriode[$h]['p_id']==\$aPerMonth[$i][$x]['fi_pid'] ".
$aPeriode[$h]['p_id']."==".$aPerMonth[$i][$x]['fi_pid'] );
@ -85,10 +90,11 @@ if (count($aPerMonth[$i]) != 0 ){
}
}
}
$amount=bcadd($amount,$amount_initial);
$estm[$i][$e][$h]=$amount;
echo nbm( $amount);
$tot_estm=bcadd($tot_estm,$amount);
$tot_cum_estm[$h]=$tot_estm;
$tot_cat_estm=bcadd($amount,$tot_cat_estm);
?>
@ -99,13 +105,15 @@ $tot_cat_estm=bcadd($amount,$tot_cat_estm);
</td>
</tr>
<tr>
<td>
<?php echo _('Réel');$tot=0;?>
</td>
<?php for ($h=0;$h<count($aPeriode);$h++):?>
<td align="right">
<?php echo nbm( $aReal[$i][$e][$h]);$tot_cat_real=bcadd($tot_cat_real,$aReal[$i][$e][$h]);
<?php echo nbm( $aReal[$i][$e][$h]);
$tot_cat_real=bcadd($tot_cat_real,$aReal[$i][$e][$h]);
$tot=bcadd($tot,$aReal[$i][$e][$h]);?>
</td>
<?php endfor;?>
@ -113,24 +121,40 @@ $tot_cat_estm=bcadd($amount,$tot_cat_estm);
<?php echo nbm( $tot);?>
</td>
</tr>
<tr>
<td>
<?php echo _('Total réel');
<tr>
<td>
<?=_('Total estimé')?>
</td>
<?php
/// row about cum. estimate amount
for ($h=0;$h<count($aPeriode);$h++):
?>
<td class="num">
<?=nbm($tot_cum_estm[$h])?>
</td>
<?php
endfor;
?>
</tr>
$tot_cat_real = 0;
?>
</td>
<?php for ($h = 0; $h < count($aPeriode); $h++):?>
<td align="right">
<?php
$tot_cat_real = bcadd($tot_cat_real, $aReal[$i][$e][$h]);
$tot_cum_real=bcadd($tot_cum_real,$aReal[$i][$e][$h]);
echo nbm($tot_cat_real);
?>
</td>
<?php endfor;?>
<tr>
<td>
<?php echo _('Total réel');
</tr>
$tot_cat_real = 0;
?>
</td>
<?php for ($h = 0; $h < count($aPeriode); $h++):?>
<td align="right">
<?php
$tot_cat_real = bcadd($tot_cat_real, $aReal[$i][$e][$h]);
$tot_cum_real=bcadd($tot_cum_real,$aReal[$i][$e][$h]);
echo nbm($tot_cat_real);
?>
</td>
<?php endfor;?>
</tr>
<tr>
<td>
<?php echo _('Différence');?>
@ -139,7 +163,8 @@ $tot_cat_estm=bcadd($amount,$tot_cat_estm);
<?php
$diff= bcsub( $aReal[$i][$e][$h],$estm[$i][$e][$h]);
if ( ($aItem[$i][$e]['fi_debit'] == 'C' && $diff < 0) || ($aItem[$i][$e]['fi_debit'] == 'D' && $diff > 0))
if ( ( $aItem[$i][$e]['fi_card']!="" && $aItem[$i][$e]['fi_debit'] == 'C' && $diff < 0)
|| ($aItem[$i][$e]['fi_card'] && $aItem[$i][$e]['fi_debit'] == 'D' && $diff > 0))
{
echo '<td style="text-align:right;background-color:red;color:white">';
}
@ -147,10 +172,14 @@ else if ($diff==0)
{
echo '<td style="text-align:right;">';
}
else
elseif ( $aItem[$i][$e]['fi_account']!="" && $diff > 0 )
{
echo '<td style="text-align:right;background-color:green;color:white">';
}
elseif ( $aItem[$i][$e]['fi_account']!="" && $diff < 0 ) {
echo '<td style="text-align:right;background-color:red;color:white">';
}
echo nbm( $diff);
?>

View file

@ -98,6 +98,11 @@ $isDebit->selected=$object->getp("fi_debit");
$isPeriode = new ISelect('fi_pid');
$isPeriode->value = $aPeriode;
$isPeriode->selected = $object->getp("fi_pid");
$amount_initial= new INum("fi_amount_initial");
$amount_initial->value=$object->getp("fi_amount_initial");
$amount_initial->value=($amount_initial->value=='')?0:$amount_initial->value;
?>
<table style="width:50rem">
<tr>
@ -146,5 +151,13 @@ $isPeriode->selected = $object->getp("fi_pid");
<td><?= _("Montant") ?></td>
<td><?= $amount->input(); ?></td>
</tr>
<tr>
<td>
<?=_("Montant initial")?>
</td>
<td>
<?=$amount_initial->input()?>
</td>
</tr>
</table>