Esempio n. 1
0
 function get_row($p_from_periode, $p_to_periode, $p_previous_exc = 0)
 {
     global $g_user;
     // filter on requested periode
     $per_sql = sql_filter_per($this->db, $p_from_periode, $p_to_periode, 'p_id', 'j_tech_per');
     $and = "";
     $jrn = "";
     $from_poste = "";
     $to_poste = "";
     /* if several ledgers are asked then we filter here  */
     if ($this->jrn !== null) {
         /**
          *@file
          *@bug the get_ledger here is not valid and useless we just need a list of the 
          * asked ledgers
          */
         $jrn = "  j_jrn_def in (";
         $comma = '';
         for ($e = 0; $e < count($this->jrn); $e++) {
             $jrn .= $comma . $this->jrn[$e];
             $comma = ',';
         }
         $jrn .= ')';
         $and = " and ";
     }
     if (strlen(trim($this->from_poste)) != 0 && $this->from_poste != -1) {
         $from_poste = " {$and} j_poste::text >= '" . $this->from_poste . "'";
         $and = " and ";
     }
     if (strlen(trim($this->to_poste)) != 0 && $this->to_poste != -1) {
         $to_poste = " {$and} j_poste::text <= '" . $this->to_poste . "'";
         $and = " and ";
     }
     $filter_sql = $g_user->get_ledger_sql('ALL', 3);
     switch ($p_previous_exc) {
         case 0:
             // build query
             $sql = "select j_poste as poste,sum(deb) as sum_deb, sum(cred) as sum_cred from\n                     ( select j_poste,\n                     case when j_debit='t' then j_montant else 0 end as deb,\n                     case when j_debit='f' then j_montant else 0 end as cred\n                     from jrnx join tmp_pcmn on (j_poste=pcm_val)\n                     left join parm_periode on (j_tech_per = p_id)\n                     join jrn_def on (j_jrn_def=jrn_def_id)\n                     where\n                     {$jrn} {$from_poste} {$to_poste}\n                     {$and} {$filter_sql}\n                     and\n                     {$per_sql} ) as m group by 1 order by 1";
             break;
         case 1:
             /*
              * retrieve balance previous exercice
              */
             $periode = new Periode($this->db);
             $previous_exc = $periode->get_exercice($p_from_periode) - 1;
             try {
                 list($previous_start, $previous_end) = $periode->get_limit($previous_exc);
                 $per_sql_previous = sql_filter_per($this->db, $previous_start->p_id, $previous_end->p_id, 'p_id', 'j_tech_per');
                 $sql = "\n                            with m as \n                                ( select j_poste,sum(deb) as sdeb,sum(cred) as scred\n                                from \n                                (select j_poste, \n                                    case when j_debit='t' then j_montant else 0 end as deb, \n                                    case when j_debit='f' then j_montant else 0 end as cred \n                                    from jrnx \n                                    join tmp_pcmn on (j_poste=pcm_val) \n                                    left join parm_periode on (j_tech_per = p_id) \n                                    join jrn_def on (j_jrn_def=jrn_def_id) \n                                    where\n                                                             {$jrn} {$from_poste} {$to_poste}\n                                    {$and} {$filter_sql} and {$per_sql}\n                                    ) as sub_m group by j_poste order by j_poste ) , \n                            p as ( select j_poste,sum(deb) as sdeb,sum(cred) as scred \n                                from \n                                    (select j_poste, \n                                        case when j_debit='t' then j_montant else 0 end as deb, \n                                        case when j_debit='f' then j_montant else 0 end as cred \n                                        from jrnx join tmp_pcmn on (j_poste=pcm_val) \n                                        left join parm_periode on (j_tech_per = p_id) \n                                        join jrn_def on (j_jrn_def=jrn_def_id) \n                                        where \n                                       {$jrn} {$from_poste} {$to_poste}\n                                    {$and} {$filter_sql} and {$per_sql_previous})  as sub_p group by j_poste order by j_poste)\n                            select coalesce(m.j_poste,p.j_poste) as poste\n                                                                ,coalesce(m.sdeb,0) as sum_deb\n                                                                , coalesce(m.scred,0) as sum_cred \n                                                                ,coalesce(p.sdeb,0) as sum_deb_previous\n                                                                , coalesce(p.scred,0) as sum_cred_previous from m full join p on (p.j_poste=m.j_poste)\n                                             order by poste";
             } catch (Exception $exc) {
                 $p_previous_exc = 0;
                 /*
                  * no previous exercice
                  */
                 $sql = "select upper(j_poste::text) as poste,sum(deb) as sum_deb, sum(cred) as sum_cred from\n                     ( select j_poste,\n                     case when j_debit='t' then j_montant else 0 end as deb,\n                     case when j_debit='f' then j_montant else 0 end as cred\n                     from jrnx join tmp_pcmn on (j_poste=pcm_val)\n                     left join parm_periode on (j_tech_per = p_id)\n                     join jrn_def on (j_jrn_def=jrn_def_id)\n                     where\n                     {$jrn} {$from_poste} {$to_poste}\n                     {$and} {$filter_sql}\n                     and\n                     {$per_sql} ) as m group by poste order by poste";
             }
             break;
     }
     $cn = clone $this->db;
     $Res = $this->db->exec_sql($sql);
     $tot_cred = 0.0;
     $tot_deb = 0.0;
     $tot_deb_saldo = 0.0;
     $tot_cred_saldo = 0.0;
     $tot_cred_previous = 0.0;
     $tot_deb_previous = 0.0;
     $tot_deb_saldo_previous = 0.0;
     $tot_cred_saldo_previous = 0.0;
     $M = $this->db->size();
     // Load the array
     for ($i = 0; $i < $M; $i++) {
         $r = $this->db->fetch($i);
         $poste = new Acc_Account($cn, $r['poste']);
         $a['poste'] = $r['poste'];
         $a['label'] = mb_substr($poste->get_lib(), 0, 40);
         $a['sum_deb'] = round($r['sum_deb'], 2);
         $a['sum_cred'] = round($r['sum_cred'], 2);
         $a['solde_deb'] = round($a['sum_deb'] >= $a['sum_cred'] ? $a['sum_deb'] - $a['sum_cred'] : 0, 2);
         $a['solde_cred'] = round($a['sum_deb'] <= $a['sum_cred'] ? $a['sum_cred'] - $a['sum_deb'] : 0, 2);
         if ($p_previous_exc == 1) {
             $a['sum_deb_previous'] = round($r['sum_deb_previous'], 2);
             $a['sum_cred_previous'] = round($r['sum_cred_previous'], 2);
             $a['solde_deb_previous'] = round($a['sum_deb_previous'] >= $a['sum_cred_previous'] ? $a['sum_deb_previous'] - $a['sum_cred_previous'] : 0, 2);
             $a['solde_cred_previous'] = round($a['sum_deb_previous'] <= $a['sum_cred_previous'] ? $a['sum_cred_previous'] - $a['sum_deb_previous'] : 0, 2);
             $tot_cred_previous += $a['sum_cred_previous'];
             $tot_deb_previous += $a['sum_deb_previous'];
             $tot_deb_saldo_previous += $a['solde_deb_previous'];
             $tot_cred_saldo_previous += $a['solde_cred_previous'];
         }
         if ($p_previous_exc == 0 && $this->unsold == true && $a['solde_cred'] == 0 && $a['solde_deb'] == 0) {
             continue;
         }
         if ($p_previous_exc == 1 && $this->unsold == true && $a['solde_cred'] == 0 && $a['solde_deb'] == 0 && $a['solde_cred_previous'] == 0 && $a['solde_deb_previous'] == 0) {
             continue;
         }
         $array[$i] = $a;
         $tot_cred += $a['sum_cred'];
         $tot_deb += $a['sum_deb'];
         $tot_deb_saldo += $a['solde_deb'];
         $tot_cred_saldo += $a['solde_cred'];
     }
     //for i
     // Add the saldo
     $i += 1;
     $a['poste'] = "";
     $a['label'] = "Totaux ";
     $a['sum_deb'] = $tot_deb;
     $a['sum_cred'] = $tot_cred;
     $a['solde_deb'] = $tot_deb_saldo;
     $a['solde_cred'] = $tot_cred_saldo;
     if ($p_previous_exc == 1) {
         $a['sum_deb_previous'] = $tot_deb_previous;
         $a['sum_cred_previous'] = $tot_cred_previous;
         $a['solde_deb_previous'] = $tot_deb_saldo_previous;
         $a['solde_cred_previous'] = $tot_cred_saldo_previous;
     }
     $array[$i] = $a;
     $this->row = $array;
     return $array;
 }
Esempio n. 2
0
 /**
 * @brief retrieve amount of previous periode
 * @param $p_to frmo the start of the exercise until $p_to
 * @return $array with vat, price,other_amount
 * @note
 * @see
  @code
  array
  'price' => string '446.1900' (length=8)
  'vat' => string '21.7600' (length=7)
  'priv' => string '0.0000' (length=6)
  'tva_nd_recup' => string '0.0000' (length=6)
  'tva' =>
  array
  0 =>
  array
  'sum_vat' => string '13.7200' (length=7)
  'tva_id' => string '1' (length=1)
  1 =>
  array
  'sum_vat' => string '8.0400' (length=6)
  'tva_id' => string '3' (length=1)
  2 =>
  array
  'sum_vat' => string '0.0000' (length=6)
  'tva_id' => string '4' (length=1)
 
  @endcode
 */
 function previous_amount($p_to)
 {
     /* get the first periode of exercise */
     $periode = new Periode($this->db, $p_to);
     $exercise = $periode->get_exercice();
     list($min, $max) = $periode->get_limit($exercise);
     // transform min into date
     $min_date = $min->first_day();
     // transform $p_to  into date
     $periode_max = new Periode($this->db, $p_to);
     $max_date = $periode_max->first_day();
     bcscale(2);
     // min periode
     if ($this->type == 'ACH') {
         /*  get all amount exclude vat */
         $sql = "select coalesce(sum(qp_price),0) as price" . " ,coalesce(sum(qp_vat),0) as vat " . ',coalesce(sum(qp_dep_priv),0) as priv' . ',coalesce(sum(qp_vat_sided),0) as reversed' . ',coalesce(sum(qp_nd_tva_recup),0)+coalesce(sum(qp_nd_tva),0) as tva_nd' . ',coalesce(sum(qp_vat_sided),0) as tva_np' . '  from quant_purchase join jrnx using(j_id) ' . " where j_date >= to_date(\$1,'DD.MM.YYYY') and j_date < to_date(\$2,'DD.MM.YYYY') " . ' and j_jrn_def = $3';
         $array = $this->db->get_array($sql, array($min_date, $max_date, $this->id));
         $ret = $array[0];
         /* retrieve all vat code */
         $array = $this->db->get_array("select coalesce(sum(qp_vat),0) as sum_vat,tva_id\n                                        from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id)  join jrnx using(j_id)\n                                        where tva_rate !=0 and  j_date >= to_date(\$1,'DD.MM.YYYY') and j_date < to_date(\$2,'DD.MM.YYYY') \n                                        and j_jrn_def = \$3\n                                        group by tva_id", array($min_date, $max_date, $this->id));
         $ret['tva'] = $array;
     }
     if ($this->type == 'VEN') {
         /*  get all amount exclude vat */
         $sql = "select coalesce(sum(qs_price),0) as price" . " ,coalesce(sum(qs_vat),0) as vat " . ',0 as priv' . ',0 as tva_nd' . ',coalesce(sum(qs_vat_sided),0) as tva_np' . '  from quant_sold join jrnx using(j_id) ' . " where j_date >= to_date(\$1,'DD.MM.YYYY') and j_date < to_date(\$2,'DD.MM.YYYY') " . ' and j_jrn_def = $3';
         $array = $this->db->get_array($sql, array($min_date, $max_date, $this->id));
         $ret = $array[0];
         /* retrieve all vat code */
         $array = $this->db->get_array("select coalesce(sum(qs_vat),0) as sum_vat,tva_id\n                                        from quant_sold as p right join tva_rate on (qs_vat_code=tva_id)  join jrnx using(j_id)\n                                        where tva_rate !=0 and\n                                        j_date >= to_date(\$1,'DD.MM.YYYY') and j_date < to_date(\$2,'DD.MM.YYYY') \n                                        and j_jrn_def = \$3\n                                        group by tva_id", array($min_date, $max_date, $this->id));
         $ret['tva'] = $array;
     }
     if ($this->type == "FIN") {
         /* find the quick code of this ledger */
         $ledger = new Acc_Ledger_Fin($this->db, $this->id);
         $qcode = $ledger->get_bank();
         $bank_card = new Fiche($this->db, $qcode);
         /*add the amount from Opening Writing                  */
         $cond = sprintf(" j_jrn_def <> %d  and j_date >= to_date('%s','DD.MM.YYYY') and j_date < to_date('%s','DD.MM.YYYY') ", $this->id, $min_date, $max_date);
         $saldo = $bank_card->get_bk_balance($cond);
         $ret['amount'] = bcsub($saldo['debit'], $saldo['credit']);
     }
     return $ret;
 }
Esempio n. 3
0
 static function parse_formula($p_cn, $p_label, $p_formula, $p_start, $p_end, $p_eval = true, $p_type_date = 0, $p_sql = "")
 {
     global $g_user;
     if (Impress::check_formula($p_formula) == false) {
         if ($p_eval == true) {
             return array('desc' => $p_label . '  Erreur Formule!', 'montant' => 0);
         } else {
             return $p_formula;
         }
     }
     if ($p_type_date == 0) {
         $cond = sql_filter_per($p_cn, $p_start, $p_end, 'p_id', 'j_tech_per');
     } else {
         $cond = "( j_date >= to_date('{$p_start}','DD.MM.YYYY') and j_date <= to_date('{$p_end}','DD.MM.YYYY'))";
     }
     include_once "class_acc_account_ledger.php";
     while (preg_match_all("(\\[[0-9]*[A-Z]*%*c*d*s*\\])", $p_formula, $e) == true) {
         // remove the [ ]
         $x = $e[0];
         foreach ($x as $line) {
             $compute = 'all';
             if (strpos($line, 'd') != 0) {
                 $compute = 'deb';
             }
             if (strpos($line, 'c') != 0) {
                 $compute = 'cred';
             }
             if (strpos($line, 's') != 0) {
                 $compute = 'signed';
             }
             $line = str_replace("[", "", $line);
             $line = str_replace("]", "", $line);
             $line = str_replace("d", "", $line);
             $line = str_replace("c", "", $line);
             $line = str_replace("s", "", $line);
             // If there is a FROM clause we must recompute
             // the time cond
             if ($p_type_date == 0 && preg_match("/FROM=[0-9]+\\.[0-9]+/", $p_formula, $afrom) == 1) {
                 // There is a FROM clause
                 // then we must modify the cond for the periode
                 $from = str_replace("FROM=", "", $afrom[0]);
                 // Get the periode
                 /*! \note special value for the clause FROM=00.0000
                  */
                 if ($from == '00.0000') {
                     // retrieve the first month of this periode
                     $user_periode = $g_user->get_periode();
                     $oPeriode = new Periode($p_cn);
                     $periode = $oPeriode->get_exercice($user_periode);
                     list($first, $last) = $oPeriode->get_limit($periode);
                     $ret = $first->get_date_limit();
                     $end_date = $oPeriode->get_date_limit($p_end);
                     if ($ret == null) {
                         throw new Exception('Pas de limite à cette période', 1);
                     }
                     $cond = sql_filter_per($p_cn, $ret['p_start'], $end_date['p_end'], 'date', 'j_tech_per');
                 } else {
                     $oPeriode = new Periode($p_cn);
                     try {
                         $pfrom = $oPeriode->find_periode('01.' . $from);
                         $cond = sql_filter_per($p_cn, $pfrom, $p_end, 'p_id', 'j_tech_per');
                     } catch (Exception $exp) {
                         /* if none periode is found
                               then we take the first periode of the year
                            */
                         $user_periode = $g_user->get_periode();
                         $year = $oPeriode->get_exercice($user_periode);
                         list($first, $last) = $oPeriode->get_limit($year);
                         $ret = $first->get_date_limit();
                         $end_date = $oPeriode->get_date_limit($p_end);
                         if ($ret == null) {
                             throw new Exception('Pas de limite à cette période', 1);
                         }
                         $cond = sql_filter_per($p_cn, $ret['p_start'], $end_date['p_end'], 'date', 'j_tech_per');
                     }
                 }
             }
             if (strpos($p_formula, "FROM") != 0) {
                 // We remove FROM out of the p_formula
                 $p_formula = substr_replace($p_formula, "", strpos($p_formula, "FROM"));
             }
             // Get sum of account
             $P = new Acc_Account_Ledger($p_cn, $line);
             $detail = $P->get_solde_detail($cond . $p_sql);
             if ($compute == 'all') {
                 $i = $detail['solde'];
             }
             if ($compute == 'deb') {
                 $i = $detail['debit'];
             }
             if ($compute == 'cred') {
                 $i = $detail['credit'];
             }
             if ($compute == 'signed') {
                 $i = $detail['debit'] - $detail['credit'];
             }
             $p_formula = str_replace($x[0], $i, $p_formula);
         }
     }
     // $p_eval is true then we eval and returns result
     if ($p_eval == true) {
         $p_formula = "\$result=" . $p_formula . ";";
         eval("{$p_formula}");
         while (preg_match("/\\[([0-9]+)([Tt]*)\\]/", trim($p_label), $e) == 1) {
             $nom = "!!" . $e[1] . "!!";
             if (Impress::check_formula($e[0])) {
                 $nom = $p_cn->get_value("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE pcm_val::text LIKE \$1||'%' ORDER BY pcm_val ASC LIMIT 1", array($e[1]));
                 if ($nom) {
                     if ($e[2] == 'T') {
                         $nom = strtoupper($nom);
                     }
                     if ($e[2] == 't') {
                         $nom = strtolower($nom);
                     }
                 }
             }
             $p_label = str_replace($e[0], $nom, $p_label);
         }
         $aret = array('desc' => $p_label, 'montant' => $result);
         return $aret;
     } else {
         // $p_eval is false we returns only the string
         return $p_formula;
     }
 }
Esempio n. 4
0
 function record_save($p_array)
 {
     global $cn;
     try {
         if (isDate($p_array['p_date']) == null) {
             throw new Exception('Date invalide');
         }
         $cn->start();
         $ch = new Stock_Change_Sql($cn);
         $ch->setp("c_comment", $p_array['p_motif']);
         $ch->setp("r_id", $p_array['p_depot']);
         $ch->setp("c_date", $p_array['p_date']);
         $ch->setp('tech_user', $_SESSION['g_user']);
         $ch->insert();
         $per = new Periode($cn);
         $periode = $per->find_periode($p_array['p_date']);
         $exercice = $per->get_exercice($periode);
         $nb = $p_array['row'];
         for ($i = 0; $i < $nb; $i++) {
             $a = new Stock_Goods_Sql($cn);
             if ($p_array['sg_quantity' . $i] != 0 && trim($p_array['sg_code' . $i]) != '') {
                 $stock = strtoupper(trim($p_array['sg_code' . $i]));
                 $fiche = new Fiche($cn);
                 $fiche->get_by_qcode($p_array['sg_code' . $i]);
                 /*
                  * check if code stock does exist
                  */
                 $count = $cn->get_value('select count(*) from fiche_detail where ad_id=$1 and ad_value=$2', array(ATTR_DEF_STOCK, $stock));
                 if ($count == 0) {
                     throw new Exception("Code stock inexistant");
                 }
                 $a->f_id = $fiche->id;
                 $a->sg_code = $stock;
                 $a->sg_quantity = abs($p_array['sg_quantity' . $i]);
                 $a->sg_type = $p_array['sg_quantity' . $i] > 0 ? 'd' : 'c';
                 $a->sg_comment = $p_array['p_motif'];
                 $a->tech_user = $_SESSION['g_user'];
                 $a->r_id = $p_array['p_depot'];
                 $a->sg_exercice = $exercice;
                 $a->c_id = $ch->c_id;
                 $a->sg_date = $p_array['p_date'];
                 $a->insert();
             }
         }
         $cn->commit();
     } catch (Exception $exc) {
         echo $exc->getTraceAsString();
         throw $exc;
     }
 }
Esempio n. 5
0
 /**
  *@brief Display a form for adding an new anticipation
  *@return html string with the form
  */
 private function form_cat_new()
 {
     global $g_user;
     $r = "";
     $str_action = _('Nouveau');
     $name = new IText('an_name');
     $str_name = $name->input();
     $start_date = new IPeriod('start_date');
     $start_date->type = ALL;
     $start_date->cn = $this->cn;
     $start_date->show_end_date = false;
     $start_date->show_start_date = true;
     $start_date->user = $g_user;
     $start_date->filter_year = false;
     $end_date = new IPeriod('end_date');
     $end_date->type = ALL;
     $end_date->cn = $this->cn;
     $end_date->show_end_date = true;
     $end_date->show_start_date = false;
     $end_date->user = $g_user;
     $end_date->filter_year = false;
     $period = $g_user->get_periode();
     $per = new Periode($this->cn, $period);
     $year = $per->get_exercice();
     list($per_start, $per_end) = $per->get_limit($year);
     $start_date->value = $per_start->p_id;
     $end_date->value = $per_end->p_id;
     $str_start_date = $start_date->input();
     $str_end_date = $end_date->input();
     $aLabel = array(_('Ventes'), _('Dépense'), _('Banque'));
     $aCat = array();
     for ($i = 0; $i < MAX_CAT; $i++) {
         /* category name */
         $name = new IText('fr_cat' . $i);
         $name->value = isset($aLabel[$i]) ? $aLabel[$i] : '';
         $aCat[$i]['name'] = $name->input();
         /* category order */
         $order = new IText('fr_order' . $i);
         $order->value = $i + 1;
         $aCat[$i]['order'] = $order->input();
     }
     ob_start();
     require_once NOALYSS_INCLUDE . '/template/forecast_cat.php';
     $r .= ob_get_contents();
     ob_end_clean();
     return $r;
 }
 public function insert($p_array = null)
 {
     global $g_parameter;
     bcscale(2);
     $internal_code = "";
     $oid = 0;
     extract($p_array);
     $ret = '';
     // Debit = banque
     $bank_id = $this->get_bank();
     $fBank = new Fiche($this->db, $bank_id);
     $e_bank_account = $fBank->strAttribut(ATTR_DEF_QUICKCODE);
     // Get the saldo
     $pPeriode = new Periode($this->db);
     $sposte = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
     // if 2 accounts, take only the debit one for customer
     if (strpos($sposte, ',') != 0) {
         $array = explode(',', $sposte);
         $poste_val = $array[0];
     } else {
         $poste_val = $sposte;
     }
     $acc_account = new Acc_Account_Ledger($this->db, $poste_val);
     // If date = deposit date
     if ($chdate == 1) {
         if ($this->check_periode() == true) {
             $pPeriode->p_id = $periode;
         } else {
             $pPeriode->find_periode($e_date);
         }
         $exercice = $pPeriode->get_exercice();
         $filter_year = "  j_tech_per in (select p_id from parm_periode where  p_exercice='" . $exercice . "')";
         $asolde = $acc_account->get_solde_detail($filter_year);
         $deb = $asolde['debit'];
         $cred = $asolde['credit'];
         $solde = bcsub($deb, $cred);
         $new_solde = $solde;
     }
     try {
         $this->db->start();
         $amount = 0.0;
         $idx_operation = 0;
         $ret = '<table class="result" >';
         $ret .= tr(th('Date') . th('n° interne') . th('Quick Code') . th('Nom') . th('Libellé') . th('Montant', ' style="text-align:right"'));
         // Credit = goods
         $get_solde = true;
         for ($i = 0; $i < $nb_item; $i++) {
             // insert it into the database
             // and quit the loop ?
             if (strlen(trim(${"e_other{$i}"})) == 0) {
                 continue;
             }
             if ($chdate == 2) {
                 $e_date = ${'dateop' . $i};
             }
             // if date is date of operation
             if ($chdate == 2 && $get_solde) {
                 $get_solde = false;
                 if ($this->check_periode() == true) {
                     $pPeriode->p_id = $periode;
                 } else {
                     $pPeriode->find_periode($e_date);
                 }
                 $exercice = $pPeriode->get_exercice();
                 $filter_year = "  j_tech_per in (select p_id from parm_periode where  p_exercice='" . $exercice . "')";
                 $solde = $acc_account->get_solde($filter_year);
                 $new_solde = $solde;
             }
             $fPoste = new Fiche($this->db);
             $fPoste->get_by_qcode(${"e_other{$i}"});
             // round it
             ${"e_other{$i}" . "_amount"} = round(${"e_other{$i}" . "_amount"}, 2);
             $amount += ${"e_other{$i}" . "_amount"};
             // Record a line for the bank
             // Compute the j_grpt
             $seq = $this->db->get_next_seq('s_grpt');
             $acc_operation = new Acc_Operation($this->db);
             $acc_operation->date = $e_date;
             $sposte = $fPoste->strAttribut(ATTR_DEF_ACCOUNT);
             // if 2 accounts
             if (strpos($sposte, ',') != 0) {
                 $array = explode(',', $sposte);
                 if (${"e_other{$i}" . "_amount"} < 0) {
                     $poste_val = $array[1];
                 } else {
                     $poste_val = $array[0];
                 }
             } else {
                 $poste_val = $sposte;
             }
             $acc_operation->poste = $poste_val;
             $acc_operation->amount = ${"e_other{$i}" . "_amount"} * -1;
             $acc_operation->grpt = $seq;
             $acc_operation->jrn = $p_jrn;
             $acc_operation->type = 'd';
             if (isset($periode)) {
                 $tperiode = $periode;
             } else {
                 $per = new Periode($this->db);
                 $tperiode = $per->find_periode($e_date);
             }
             $acc_operation->periode = $tperiode;
             $acc_operation->qcode = ${"e_other" . $i};
             $j_id = $acc_operation->insert_jrnx();
             $acc_operation = new Acc_Operation($this->db);
             $acc_operation->date = $e_date;
             $sposte = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
             // if 2 accounts
             if (strpos($sposte, ',') != 0) {
                 $array = explode(',', $sposte);
                 if (${"e_other{$i}" . "_amount"} < 0) {
                     $poste_val = $array[1];
                 } else {
                     $poste_val = $array[0];
                 }
             } else {
                 $poste_val = $sposte;
             }
             $acc_operation->poste = $poste_val;
             $acc_operation->amount = ${"e_other{$i}" . "_amount"};
             $acc_operation->grpt = $seq;
             $acc_operation->jrn = $p_jrn;
             $acc_operation->type = 'd';
             $acc_operation->periode = $tperiode;
             $acc_operation->qcode = $e_bank_account;
             $acc_operation->insert_jrnx();
             if (sql_string(${"e_other{$i}" . "_comment"}) == null) {
                 // if comment is blank set a default one
                 $comment = "  compte : " . $fBank->strAttribut(ATTR_DEF_NAME) . ' a ' . $fPoste->strAttribut(ATTR_DEF_NAME);
             } else {
                 $comment = ${'e_other' . $i . '_comment'};
             }
             $acc_operation = new Acc_Operation($this->db);
             $acc_operation->jrn = $p_jrn;
             $acc_operation->amount = abs(${"e_other{$i}" . "_amount"});
             $acc_operation->date = $e_date;
             $acc_operation->desc = $comment;
             $acc_operation->grpt = $seq;
             $acc_operation->periode = $tperiode;
             $acc_operation->mt = $mt;
             $idx_operation++;
             $acc_operation->pj = '';
             if (trim($e_pj) != '' && $this->numb_operation() == true) {
                 $acc_operation->pj = $e_pj . str_pad($idx_operation, 3, 0, STR_PAD_LEFT);
             }
             if (trim($e_pj) != '' && $this->numb_operation() == false) {
                 $acc_operation->pj = $e_pj;
             }
             $jr_id = $acc_operation->insert_jrn();
             // 	  $acc_operation->set_pj();
             $this->db->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj, $jr_id));
             $internal = $this->compute_internal_code($seq);
             if (trim(${"e_concerned" . $i}) != "") {
                 if (strpos(${"e_concerned" . $i}, ',') != 0) {
                     $aRapt = explode(',', ${"e_concerned" . $i});
                     foreach ($aRapt as $rRapt) {
                         // Add a "concerned operation to bound these op.together
                         //
                         $rec = new Acc_Reconciliation($this->db);
                         $rec->set_jr_id($jr_id);
                         if (isNumber($rRapt) == 1) {
                             $rec->insert($rRapt);
                         }
                     }
                 } else {
                     if (isNumber(${"e_concerned" . $i}) == 1) {
                         $rec = new Acc_Reconciliation($this->db);
                         $rec->set_jr_id($jr_id);
                         $rec->insert(${"e_concerned{$i}"});
                     }
                 }
             }
             // Set Internal code
             $this->grpt_id = $seq;
             /**
              * save also into quant_fin
              */
             $this->insert_quant_fin($fBank->id, $jr_id, $fPoste->id, ${"e_other{$i}" . "_amount"});
             if ($g_parameter->MY_ANALYTIC != "nu") {
                 // for each item, insert into operation_analytique */
                 $op = new Anc_Operation($this->db);
                 $op->oa_group = $this->db->get_next_seq("s_oa_group");
                 /* for analytic */
                 $op->j_id = $j_id;
                 $op->oa_date = $e_date;
                 $op->oa_debit = 'f';
                 $op->oa_description = sql_string($comment);
                 $op->save_form_plan($_POST, $i, $j_id);
             }
             $this->update_internal_code($internal);
             $js_detail = HtmlInput::detail_op($jr_id, $internal);
             // Compute display
             $row = td($e_date) . td($js_detail) . td(${"e_other{$i}"}) . td($fPoste->strAttribut(ATTR_DEF_NAME)) . td(${"e_other" . $i . "_comment"}) . td(nbm(${"e_other{$i}" . "_amount"}), 'class="num"');
             $class = $i % 2 == 0 ? ' class="even" ' : ' class="odd" ';
             $ret .= tr($row, $class);
             if ($i == 0) {
                 // first record we upload the files and
                 // keep variable to update other row of jrn
                 if (isset($_FILES)) {
                     $oid = $this->db->save_upload_document($seq);
                 }
             } else {
                 if ($oid != 0) {
                     $this->db->exec_sql("update jrn set jr_pj=\$1 , jr_pj_name=\$2,\n                                            jr_pj_type=\$3  where jr_grpt_id=\$4", array($oid, $_FILES['pj']['name'], $_FILES['pj']['type'], $seq));
                 }
             }
         }
         // for nbitem
         // increment pj
         if (strlen(trim($e_pj)) != 0) {
             $this->inc_seq_pj();
         }
         $ret .= '</table>';
     } catch (Exception $e) {
         $r = '<span class="error">' . 'Erreur dans l\'enregistrement ' . __FILE__ . ':' . __LINE__ . ' ' . $e->getMessage();
         $this->db->rollback();
         throw new Exception($r);
     }
     $this->db->commit();
     $r = "";
     $r .= "<br>Ancien solde " . nbm($solde);
     $new_solde = bcadd($new_solde, $amount);
     $r .= "<br>Nouveau solde " . nbm($new_solde);
     $ret .= $r;
     return $ret;
 }