Example #1
0
function sql_filter_per($p_cn, $p_from, $p_to, $p_form = 'p_id', $p_field = 'jr_tech_per')
{
    if ($p_form != 'p_id' && $p_form != 'date') {
        echo_error(__FILE__, __LINE__, 'Mauvais parametres ');
        exit(-1);
    }
    if ($p_form == 'p_id') {
        // retrieve the date
        $pPeriode = new Periode($p_cn);
        $a_start = $pPeriode->get_date_limit($p_from);
        $a_end = $pPeriode->get_date_limit($p_to);
        if ($a_start == null || $a_end == null) {
            throw new Exception(__FILE__ . __LINE__ . sprintf(_('Attention periode 
		     non trouvee periode p_from= %s p_to_periode = %s'), $p_from, $p_to));
        }
        $p_from = $a_start['p_start'];
        $p_to = $a_end['p_end'];
    }
    if ($p_from == $p_to) {
        $periode = " {$p_field} = (select p_id from parm_periode " . " where " . " p_start = to_date('{$p_from}','DD.MM.YYYY')) ";
    } else {
        $periode = "{$p_field} in (select p_id from parm_periode " . " where p_start >= to_date('{$p_from}','DD.MM.YYYY') and p_end <= to_date('{$p_to}','DD.MM.YYYY')) ";
    }
    return $periode;
}
 function html_table($p_from)
 {
     if ($p_from == "") {
         $from = "";
         $to = "";
     } else {
         $p = new Periode($this->db);
         list($from, $to) = $p->get_date_limit($p_from);
     }
     $array = $this->get_list($from, $to);
     if (empty($array)) {
         return "Pas d'enregistrement trouv&eacute;";
     }
     // navigation_bar
     $step = $_SESSION['g_pagesize'];
     $page = isset($_GET['offset']) ? $_GET['page'] : 1;
     $offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
     $bar = navigation_bar($offset + 1, count($array), $step, $page);
     if ($step != -1) {
         $view = array_splice($array, $offset, $step);
     } else {
         $view = $array;
     }
     $gDossier = dossier::id();
     $ret = "";
     $ret .= $bar;
     $count = 0;
     $group = 0;
     $oldgroup = 0;
     $oldjrid = 0;
     foreach ($view as $row) {
         $group = $row['oa_group'];
         if ($group != $oldgroup) {
             if ($oldgroup != 0) {
                 $efface = new IButton();
                 $efface->javascript = "anc_remove_operation(" . $gDossier . "," . $oldgroup . ")";
                 $efface->name = "Efface";
                 $efface->label = "Efface";
                 $ret .= "<td>" . $efface->input() . "</td>";
                 $this->oa_group = $oldgroup;
                 $jr_id = $this->get_jrid();
                 if ($jr_id != 0) {
                     // get the old jr_id
                     $detail = new IButton();
                     $detail->javascript = "viewOperation({$jr_id},{$gDossier})";
                     $detail->name = "Detail";
                     $detail->label = "Detail";
                     $ret .= "<td>" . $detail->input() . "</td>";
                 }
                 $ret .= '</table>';
             }
             $ret .= '<table id="' . $row['oa_group'] . '" class="result">';
             $ret .= "<tr class=\"highlight\">" . td($row['oa_date']) . "<td>" . HtmlInput::detail_op($row['jr_id'], h($row['oa_description'] . " " . $row['jr_pj_number'])) . "</td>" . td();
             $ret .= "<td>" . "Groupe id : " . $row['oa_group'] . "</td>" . ($oldgroup = $group);
         }
         $class = $count % 2 == 0 ? "odd" : "even";
         $count++;
         $cred = $row['oa_debit'] == 'f' ? "CREDIT" : "DEBIT";
         $ret .= "<tr class=\"{$class}\">";
         $ret .= "<td>" . h($row['po_name']) . "</td>";
         $ret .= td(h($row['po_description']));
         $ret .= '<td class="num">' . nbm($row['oa_amount']) . "</td>" . "<td>" . $cred . "</td>" . "</tr>";
     }
     $efface = new IButton();
     $efface->javascript = "anc_remove_operation(" . "{$gDossier}," . $oldgroup . ")";
     $efface->name = "Efface";
     $efface->label = "Efface";
     $ret .= "<td>" . $efface->input() . "</td>";
     // get the old jr_id
     $this->oa_group = $oldgroup;
     $jr_id = $this->get_jrid();
     if ($jr_id != 0) {
         $detail = new IButton();
         $detail->javascript = "modifyOperation({$jr_id},'" . $gDossier . "')";
         $detail->name = "Detail";
         $detail->label = "Detail";
         $ret .= "<td>" . $detail->input() . "</td>";
     }
     $ret .= '</table>';
     $ret .= $bar;
     return $ret;
 }
Example #3
0
 if ($_GET['p_filter'] == 0) {
     $bal->jrn = null;
 }
 if ($_GET['p_filter'] == 2 && isset($_GET['r_cat'])) {
     $bal->filter_cat($_GET['r_cat']);
 }
 $bal->from_poste = $_GET['from_poste'];
 $bal->to_poste = $_GET['to_poste'];
 if (isset($_GET['unsold'])) {
     $bal->unsold = true;
 }
 $previous = isset($_GET['previous_exc']) ? 1 : 0;
 $row = $bal->get_row($_GET['from_periode'], $_GET['to_periode'], $previous);
 $previous = isset($row[0]['sum_cred_previous']) ? 1 : 0;
 $periode = new Periode($cn);
 $a = $periode->get_date_limit($_GET['from_periode']);
 $b = $periode->get_date_limit($_GET['to_periode']);
 echo "<h2 class=\"info\"> période du " . $a['p_start'] . " au " . $b['p_end'] . "</h2>";
 echo '<span style="display:block">';
 echo _('Filtre') . HtmlInput::infobulle(24);
 echo HtmlInput::filter_table("t_balance", "0,1", "1");
 echo '</span>';
 echo '<table id="t_balance" width="100%">';
 echo '<th>Poste Comptable</th>';
 echo '<th>Libell&eacute;</th>';
 if ($previous == 1) {
     echo '<th>D&eacute;bit N-1</th>';
     echo '<th>Cr&eacute;dit N-1</th>';
     echo '<th>Solde D&eacute;biteur N-1</th>';
     echo '<th>Solde Cr&eacute;diteur N-1</th>';
     if (isset($_GET['lvl1']) || isset($_GET['lvl2']) || isset($_GET['lvl3'])) {
    exit - 1;
}
$Ledger->id = $p_jrn;
echo $Ledger->display_search_form();
//------------------------------
// UPdate the payment
//------------------------------
if (isset($_GET['paid'])) {
    $Ledger->update_paid($_GET);
}
$msg = "";
/* by default we should use the default period */
if (!isset($p_array['date_start'])) {
    $period = $g_user->get_periode();
    $per = new Periode($cn, $period);
    list($date_start, $date_end) = $per->get_date_limit();
    $p_array['date_start'] = $date_start;
    $p_array['date_end'] = $date_end;
    $msg = '<h2 class="info2">' . _("Période ") . $date_start . _(" au ") . $date_end . '</h2>';
} else {
    $msg = '<h2 class="info2">' . _("Période ") . $_GET['date_start'] . _(" au ") . $_GET['date_end'] . '</h2>';
}
/*  compute the sql stmt */
list($sql, $where) = $Ledger->build_search_sql($p_array);
$max_line = $cn->count_sql($sql);
$step = $_SESSION['g_pagesize'];
$page = isset($_GET['offset']) ? $_GET['page'] : 1;
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
$bar = navigation_bar($offset, $max_line, $step, $page);
echo $msg;
echo '<form method="GET" id="fpaida" class="print">';
Example #5
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;
     }
 }
Example #6
0
 /**
 * @brief this function will create a sql stmt to use to create the list for
 * the ledger,
 * @param$p_array is usually the $_GET,
 * @param$p_order the order of the row
 * @param$p_where is the sql condition if not null then the $p_array will not be used
 * \note the p_action will be used to filter the ledger but gl means ALL
 * struct array $p_array
  \verbatim
  (
  [gDossier] => 13
  [p_jrn] => -1
  [date_start] =>
  [date_end] =>
  [amount_min] => 0
  [amount_max] => 0
  [desc] =>
  [search] => Rechercher
  [p_action] => ven
  [sa] => l
  )
  \endverbatim
 * \return an array with a valid sql statement, an the where clause => array[sql] array[where]
 * \see list_operation
 * \see display_search_form
 * \see search_form
 */
 public function build_search_sql($p_array, $p_order = "", $p_where = "")
 {
     $sql = "select jr_id\t,\n             jr_montant,\n             substr(jr_comment,1,60) as jr_comment,\n             to_char(jr_ech,'DD.MM.YY') as str_jr_ech,\n             to_char(jr_date,'DD.MM.YY') as str_jr_date,\n             jr_date as jr_date_order,\n             jr_grpt_id,\n             jr_rapt,\n             jr_internal,\n             jrn_def_id,\n             jrn_def_name,\n             jrn_def_ech,\n             jrn_def_type,\n             jr_valid,\n             jr_tech_per,\n             jr_pj_name,\n             p_closed,\n             jr_pj_number,\n             n_text,\n\t     case\n\t     when jrn_def_type='VEN' then\n\t\t (select ad_value from fiche_detail where ad_id=1\n\t\t and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))\n\t    when jrn_def_type = 'ACH' then\n\t\t(select ad_value from fiche_detail where ad_id=1\n\t\tand f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))\n\t    when jrn_def_type = 'FIN' then\n\t\t(select ad_value from fiche_detail where ad_id=1\n\t\tand f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))\n\t    end as name,\n\t   case\n\t     when jrn_def_type='VEN' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))\n\t    when jrn_def_type = 'ACH' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))\n\t    when jrn_def_type = 'FIN' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))\n\t    end as first_name,\n\t    case\n\t     when jrn_def_type='VEN' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))\n\t    when jrn_def_type = 'ACH' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))\n\t    when jrn_def_type = 'FIN' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))\n\t    end as quick_code,\n\t    case\n\t     when jrn_def_type='VEN' then\n\t\t     (select sum(qs_price)+sum(vat) from\n\t\t\t\t(select qs_internal,qs_price,case when qs_vat_sided<>0 then 0 else qs_vat end as vat from quant_sold where qs_internal=X.jr_internal) as ven_invoice\n\t\t\t  )\n\t    when jrn_def_type = 'ACH' then\n\t\t\t(\n\t\t\t\tselect sum(qp_price)+sum(vat)+sum(qp_nd_tva)+sum(qp_nd_tva_recup)\n\t\t\t\tfrom\n\t\t\t\t (select qp_internal,qp_price,qp_nd_tva,qp_nd_tva_recup,qp_vat-qp_vat_sided as vat from quant_purchase where qp_internal=X.jr_internal) as invoice_purchase\n\t\t\t)\n\t\telse null\n\t\tend as total_invoice,\n            jr_date_paid,\n            to_char(jr_date_paid,'DD.MM.YY') as str_jr_date_paid\n             from\n             jrn as X left join jrn_note using(jr_id)\n             join jrn_def on jrn_def_id=jr_def_id\n             join parm_periode on p_id=jr_tech_per";
     if (!empty($p_array)) {
         extract($p_array);
     }
     if (isset($op)) {
         $r_jrn = isset(${$op . "r_jrn"}) ? ${$op . "r_jrn"} : -1;
     } else {
         $r_jrn = isset($r_jrn) ? $r_jrn : -1;
     }
     /* if no variable are set then give them a default
      * value */
     if ($p_array == null || empty($p_array) || !isset($amount_min)) {
         $amount_min = 0;
         $amount_max = 0;
         $desc = '';
         $qcode = isset($qcode) ? $qcode : "";
         if (isset($qcodesearch_op)) {
             $qcode = $qcodesearch_op;
         }
         $accounting = isset($accounting) ? $accounting : "";
         $periode = new Periode($this->db);
         $g_user = new User($this->db);
         $p_id = $g_user->get_periode();
         if ($p_id != null) {
             list($date_start, $date_end) = $periode->get_date_limit($p_id);
         }
     }
     /* if p_jrn : 0 if means all ledgers, if -1 means all ledger of this
      *  type otherwise only one ledger */
     $fil_ledger = '';
     $fil_amount = '';
     $fil_date = '';
     $fil_desc = '';
     $fil_sec = '';
     $fil_qcode = '';
     $fil_account = '';
     $fil_paid = '';
     $fil_date_paid = '';
     $and = '';
     $g_user = new User($this->db);
     $p_action = $ledger_type;
     if ($p_action == '') {
         $p_action = 'ALL';
     }
     if ($r_jrn == -1) {
         /* from compta.php the p_action is quick_writing instead of ODS  */
         if ($p_action == 'quick_writing') {
             $p_action = 'ODS';
         }
         $fil_ledger = $g_user->get_ledger_sql($p_action, 3);
         $and = ' and ';
     } else {
         if ($p_action == 'quick_writing') {
             $p_action = 'ODS';
         }
         $aLedger = $g_user->get_ledger($p_action, 3);
         $fil_ledger = '';
         $sp = '';
         for ($i = 0; $i < count($r_jrn); $i++) {
             if (isset($r_jrn[$i])) {
                 $a = $r_jrn[$i];
                 $fil_ledger .= $sp . $a;
                 $sp = ',';
             }
         }
         $fil_ledger = ' jrn_def_id in (' . $fil_ledger . ')';
         $and = ' and ';
         /* no ledger selected */
         if ($sp == '') {
             $fil_ledger = '';
             $and = '';
         }
     }
     /* format the number */
     $amount_min = abs(toNumber($amount_min));
     $amount_max = abs(toNumber($amount_max));
     if ($amount_min > 0 && isNumber($amount_min)) {
         $fil_amount = $and . ' jr_montant >=' . $amount_min;
         $and = ' and ';
     }
     if ($amount_max > 0 && isNumber($amount_max)) {
         $fil_amount .= $and . ' jr_montant <=' . $amount_max;
         $and = ' and ';
     }
     /* -------------------------------------------------------------------------- *
      * if both amount are the same then we need to search into the detail
      * and we reset the fil_amount
      * -------------------------------------------------------------------------- */
     if (isNumber($amount_min) && isNumber($amount_max) && $amount_min > 0 && bccomp($amount_min, $amount_max, 2) == 0) {
         $fil_amount = $and . ' ( ';
         // Look in detail
         $fil_amount .= 'jr_grpt_id in ( select distinct j_grpt from jrnx where j_montant = ' . $amount_min . ') ';
         //and the total operation
         $fil_amount .= ' or ';
         $fil_amount .= ' jr_montant = ' . $amount_min;
         $fil_amount .= ')';
         $and = " and ";
     }
     // date
     if (isset($date_start) && isDate($date_start) != null) {
         $fil_date = $and . " jr_date >= to_date('" . $date_start . "','DD.MM.YYYY')";
         $and = " and ";
     }
     if (isset($date_end) && isDate($date_end) != null) {
         $fil_date .= $and . " jr_date <= to_date('" . $date_end . "','DD.MM.YYYY')";
         $and = " and ";
     }
     // date paiement
     if (isset($date_paid_start) && isDate($date_paid_start) != null) {
         $fil_date_paid = $and . " jr_date_paid >= to_date('" . $date_paid_start . "','DD.MM.YYYY')";
         $and = " and ";
     }
     if (isset($date_paid_end) && isDate($date_paid_end) != null) {
         $fil_date_paid .= $and . " jr_date_paid <= to_date('" . $date_paid_end . "','DD.MM.YYYY')";
         $and = " and ";
     }
     // comment
     if (isset($desc) && $desc != null) {
         $desc = sql_string($desc);
         $fil_desc = $and . " ( upper(jr_comment) like upper('%" . $desc . "%') or upper(jr_pj_number) like upper('%" . $desc . "%') " . " or upper(jr_internal)  like upper('%" . $desc . "%')\n                          or jr_grpt_id in (select j_grpt from jrnx where j_text ~* '" . $desc . "')\n                          or jr_id in (select jr_id from jrn_info where ji_value is not null and ji_value ~* '{$desc}')\n                          )";
         $and = " and ";
     }
     //    Poste
     if (isset($accounting) && $accounting != null) {
         $fil_account = $and . "  jr_grpt_id in (select j_grpt\n                         from jrnx where j_poste::text like '" . sql_string($accounting) . "%' )  ";
         $and = " and ";
     }
     // Quick Code
     if (isset($qcodesearch_op)) {
         $qcode = $qcodesearch_op;
     }
     if (isset($qcode) && $qcode != null) {
         $fil_qcode = $and . "  jr_grpt_id in ( select j_grpt from\n                       jrnx where trim(j_qcode) = upper(trim('" . sql_string($qcode) . "')))";
         $and = " and ";
     }
     // Only the unpaid
     if (isset($unpaid)) {
         $fil_paid = $and . SQL_LIST_UNPAID_INVOICE;
         $and = " and ";
     }
     $g_user = new User(new Database());
     $g_user->Check();
     $g_user->check_dossier(dossier::id());
     if ($g_user->admin == 0 && $g_user->is_local_admin() == 0) {
         $fil_sec = $and . " jr_def_id in ( select uj_jrn_id " . " from user_sec_jrn where " . " uj_login='******'g_user'] . "'" . " and uj_priv in ('R','W'))";
     }
     $where = $fil_ledger . $fil_amount . $fil_date . $fil_desc . $fil_sec . $fil_amount . $fil_qcode . $fil_paid . $fil_account . $fil_date_paid;
     $sql .= " where " . $where;
     return array($sql, $where);
 }
        }
        break;
}
$bal->from_poste = $_GET['from_poste'];
$bal->to_poste = $_GET['to_poste'];
if (isset($_GET['unsold'])) {
    $bal->unsold = true;
}
$previous = isset($_GET['previous_exc']) ? 1 : 0;
$array = $bal->get_row($from_periode, $to_periode, $previous);
$previous = isset($array[0]['sum_cred_previous']) ? 1 : 0;
if (sizeof($array) == 0) {
    exit;
}
$pPeriode = new Periode($cn);
$a = $pPeriode->get_date_limit($from_periode);
$b = $pPeriode->get_date_limit($to_periode);
$per_text = "  du " . $a['p_start'] . " au " . $b['p_end'];
if ($previous == 1) {
    $pdf = new PDFLand($cn);
} else {
    $pdf = new PDF($cn);
}
$pdf->setDossierInfo(" Balance  " . $per_text);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetAuthor('NOALYSS');
$pdf->SetFont('DejaVuCond', '', 7);
$pdf->setTitle("Balance comptable", true);
$pdf->Cell(30, 6, 'poste');
$pdf->LongLine(60, 6, 'Libellé');
 function input($p_array = null, $p_readonly = 0)
 {
     global $g_parameter, $g_user;
     if ($p_array != null) {
         extract($p_array);
     }
     $flag_tva = $g_parameter->MY_TVA_USE;
     /* Add button */
     $f_add_button = new IButton('add_card');
     $f_add_button->tabindex = -1;
     $f_add_button->label = _('Créer une nouvelle fiche');
     $f_add_button->set_attribute('ipopup', 'ipop_newcard');
     $f_add_button->set_attribute('jrn', $this->id);
     $f_add_button->javascript = "this.jrn=\$('p_jrn').value; select_card_type(this);";
     $f_add_button2 = new IButton('add_card2');
     $f_add_button2->tabindex = -1;
     $f_add_button2->label = _('Créer une nouvelle fiche');
     $f_add_button2->set_attribute('ipopup', 'ipop_newcard');
     $f_add_button2->set_attribute('filter', $this->get_all_fiche_def());
     //    $f_add_button2->set_attribute('jrn',$this->id);
     $f_add_button2->javascript = " this.jrn=\$('p_jrn').value;select_card_type(this);";
     $str_add_button = "";
     $str_add_button2 = "";
     if ($g_user->check_action(FICADD) == 1) {
         $str_add_button = $f_add_button->input();
         $str_add_button2 = $f_add_button2->input();
     }
     // The first day of the periode
     $oPeriode = new Periode($this->db);
     list($l_date_start, $l_date_end) = $oPeriode->get_date_limit($g_user->get_periode());
     if ($g_parameter->MY_DATE_SUGGEST == 'Y') {
         $op_date = !isset($e_date) ? $l_date_start : $e_date;
     } else {
         $op_date = !isset($e_date) ? '' : $e_date;
     }
     $e_ech = isset($e_ech) ? $e_ech : "";
     $e_comm = isset($e_comm) ? $e_comm : "";
     $r = '';
     $r .= dossier::hidden();
     $f_legend = _('Client');
     $Echeance = new IDate();
     $Echeance->setReadOnly(false);
     $Echeance->tabindex = 2;
     $label = HtmlInput::infobulle(4);
     $f_echeance = $Echeance->input('e_ech', $e_ech, _('Echéance') . $label);
     $Date = new IDate();
     $Date->setReadOnly(false);
     $f_date = $Date->input("e_date", $op_date);
     $f_periode = '';
     // Periode
     //--
     if ($this->check_periode() == true) {
         $l_user_per = $g_user->get_periode();
         $def = isset($periode) ? $periode : $l_user_per;
         $period = new IPeriod("period");
         $period->user = $g_user;
         $period->cn = $this->db;
         $period->value = $def;
         $period->type = OPEN;
         try {
             $l_form_per = $period->input();
         } catch (Exception $e) {
             if ($e->getCode() == 1) {
                 throw new Exception(_("Aucune période ouverte"));
             }
         }
         $label = HtmlInput::infobulle(3);
         $f_periode = '<td>' . _("Période comptable") . "</td> <td> {$label} " . $l_form_per . '</td>';
     }
     /* if we suggest the next pj, then we need a javascript */
     $add_js = "";
     if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
         $add_js = "update_pj();";
     }
     if ($g_parameter->MY_DATE_SUGGEST == 'Y') {
         $add_js .= 'get_last_date();';
     }
     $add_js .= 'update_name();';
     $add_js .= 'update_pay_method();';
     $add_js .= 'update_row("sold_item");';
     $wLedger = $this->select_ledger('VEN', 2);
     if ($wLedger == null) {
         throw new Exception(_('Pas de journal disponible'));
     }
     $wLedger->table = 1;
     $wLedger->javascript = "onChange='update_predef(\"ven\",\"f\",\"" . $_REQUEST['ac'] . "\");{$add_js}'";
     $wLedger->label = " Journal " . HtmlInput::infobulle(2);
     $f_jrn = $wLedger->input();
     $Commentaire = new IText();
     $Commentaire->table = 0;
     $Commentaire->setReadOnly(false);
     $Commentaire->size = 60;
     $Commentaire->tabindex = 3;
     $label = HtmlInput::infobulle(1);
     $f_desc = $Commentaire->input("e_comm", h($e_comm));
     // PJ
     //--
     /* suggest PJ ? */
     $default_pj = '';
     if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
         $default_pj = $this->guess_pj();
     }
     $pj = new IText();
     $pj->table = 0;
     $pj->name = "e_pj";
     $pj->size = 10;
     $pj->value = isset($e_pj) ? $e_pj : $default_pj;
     $f_pj = $pj->input() . HtmlInput::hidden('e_pj_suggest', $default_pj);
     // Display the customer
     //--
     $fiche = 'deb';
     // Save old value and set a new one
     //--
     $e_client = isset($e_client) ? $e_client : "";
     $e_client_label = "&nbsp;";
     //str_pad("",100,".");
     // retrieve e_client_label
     //--
     if (strlen(trim($e_client)) != 0) {
         $fClient = new Fiche($this->db);
         $fClient->get_by_qcode($e_client);
         $e_client_label = $fClient->strAttribut(ATTR_DEF_NAME) . ' ' . ' Adresse : ' . $fClient->strAttribut(ATTR_DEF_ADRESS) . ' ' . $fClient->strAttribut(ATTR_DEF_CP) . ' ' . $fClient->strAttribut(ATTR_DEF_CITY) . ' ';
     }
     $W1 = new ICard();
     $W1->label = "Client " . HtmlInput::infobulle(0);
     $W1->name = "e_client";
     $W1->tabindex = 3;
     $W1->value = $e_client;
     $W1->table = 0;
     $W1->set_dblclick("fill_ipopcard(this);");
     $W1->set_attribute('ipopup', 'ipopcard');
     // name of the field to update with the name of the card
     $W1->set_attribute('label', 'e_client_label');
     // name of the field to update with the name of the card
     $W1->set_attribute('typecard', 'deb');
     // Add the callback function to filter the card on the jrn
     $W1->set_callback('filter_card');
     $W1->set_function('fill_data');
     $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
     $f_client_qcode = $W1->input();
     $client_label = new ISpan();
     $client_label->table = 0;
     $f_client = $client_label->input("e_client_label", $e_client_label);
     $f_client_bt = $W1->search();
     // Record the current number of article
     $Hid = new IHidden();
     $p_article = isset($nb_item) ? $nb_item : $this->get_min_row();
     $r .= $Hid->input("nb_item", $p_article);
     $max = $p_article < $this->get_min_row() ? $this->get_min_row() : $p_article;
     $f_legend_detail = _("Détail articles vendus");
     // For each article
     //--
     for ($i = 0; $i < $max; $i++) {
         // Code id, price & vat code
         //--
         $march = isset(${"e_march{$i}"}) ? ${"e_march{$i}"} : "";
         $march_price = isset(${"e_march" . $i . "_price"}) ? ${"e_march" . $i . "_price"} : "";
         if ($flag_tva == 'Y') {
             $march_tva_id = isset(${"e_march{$i}" . "_tva_id"}) ? ${"e_march{$i}" . "_tva_id"} : "";
             $march_tva_amount = isset(${"e_march{$i}" . "_tva_amount"}) ? ${"e_march{$i}" . "_tva_amount"} : "";
         }
         $march_label = isset(${"e_march" . $i . "_label"}) ? ${"e_march" . $i . "_label"} : "";
         // retrieve the tva label and name
         //--
         if (strlen(trim($march)) != 0 && strlen(trim($march_label)) == 0) {
             $fMarch = new Fiche($this->db);
             $fMarch->get_by_qcode($march);
             $march_label = $fMarch->strAttribut(ATTR_DEF_NAME);
             if ($flag_tva == 'Y') {
                 if (!isset(${"e_march{$i}" . "_tva_id"})) {
                     $march_tva_id = $fMarch->strAttribut(ATTR_DEF_TVA);
                 }
             }
         }
         // Show input
         //--
         $W1 = new ICard();
         $W1->label = "";
         $W1->name = "e_march" . $i;
         $W1->value = $march;
         $W1->table = 1;
         $W1->set_attribute('typecard', 'cred');
         $W1->set_dblclick("fill_ipopcard(this);");
         $W1->set_attribute('ipopup', 'ipopcard');
         // name of the field to update with the name of the card
         $W1->set_attribute('label', 'e_march' . $i . '_label');
         // name of the field with the price
         $W1->set_attribute('price', 'e_march' . $i . '_price');
         // name of the field with the TVA_ID
         $W1->set_attribute('tvaid', 'e_march' . $i . '_tva_id');
         // Add the callback function to filter the card on the jrn
         $W1->set_callback('filter_card');
         $W1->set_function('fill_data');
         $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
         $W1->readonly = false;
         $array[$i]['quick_code'] = $W1->input();
         $array[$i]['bt'] = $W1->search();
         // For computing we need some hidden field for holding the value
         $array[$i]['hidden'] = '';
         if ($flag_tva == 'Y') {
             $array[$i]['hidden'] .= HtmlInput::hidden('tva_march' . $i, 0);
         }
         $htva = new INum('htva_march' . $i);
         $htva->readOnly = 1;
         $htva->value = 0;
         $array[$i]['htva'] = $htva->input();
         if ($g_parameter->MY_TVA_USE == 'Y') {
             $tvac = new INum('tvac_march' . $i);
         } else {
             $tvac = new IHidden('tvac_march' . $i);
         }
         $tvac->readOnly = 1;
         $tvac->value = 0;
         $array[$i]['tvac'] = $tvac->input();
         if ($g_parameter->MY_UPDLAB == 'Y') {
             $Span = new IText("e_march" . $i . "_label");
             $Span->css_size = "100%";
         } else {
             $Span = new ISpan("e_march" . $i . "_label");
         }
         $Span->value = $march_label;
         $Span->setReadOnly(false);
         // card's name, price
         //--
         $array[$i]['denom'] = $Span->input("e_march" . $i . "_label", $march_label);
         // price
         $Price = new INum();
         $Price->setReadOnly(false);
         $Price->size = 9;
         $Price->javascript = "onBlur='format_number(this);clean_tva({$i});compute_ledger({$i})'";
         $array[$i]['pu'] = $Price->input("e_march" . $i . "_price", $march_price);
         $array[$i]['tva'] = '';
         $array[$i]['amount_tva'] = '';
         // if tva is not needed then no tva field
         if ($flag_tva == 'Y') {
             // vat label
             //--
             $Tva = new ITva_Popup($this->db);
             $Tva->in_table = true;
             $Tva->set_attribute('compute', $i);
             $Tva->js = 'onblur="format_number(this);clean_tva(' . $i . ');compute_ledger(' . $i . ')"';
             $Tva->value = $march_tva_id;
             $array[$i]['tva'] = $Tva->input("e_march{$i}" . "_tva_id");
             // vat amount
             //--
             $wTva_amount = new INum();
             $wTva_amount->readOnly = false;
             $wTva_amount->size = 6;
             $wTva_amount->javascript = "onBlur='format_number(this);compute_ledger({$i})'";
             $array[$i]['amount_tva'] = $wTva_amount->input("e_march" . $i . "_tva_amount", $march_tva_amount);
         }
         // quantity
         //--
         $quant = isset(${"e_quant{$i}"}) ? ${"e_quant{$i}"} : "1";
         $Quantity = new INum();
         $Quantity->setReadOnly(false);
         $Quantity->size = 8;
         $Quantity->javascript = "onChange='format_number(this);clean_tva({$i});compute_ledger({$i})'";
         $array[$i]['quantity'] = $Quantity->input("e_quant" . $i, $quant);
     }
     // foreach article
     $f_type = _('Client');
     ob_start();
     require_once NOALYSS_INCLUDE . '/template/form_ledger_detail.php';
     $r .= ob_get_contents();
     ob_end_clean();
     // Set correctly the REQUEST param for jrn_type
     $r .= HtmlInput::hidden('jrn_type', 'VEN');
     $r .= HtmlInput::button('add_item', _('Ajout article'), ' onClick="ledger_add_row()"');
     $r .= create_script("\$('" . $Date->id . "').focus()");
     return $r;
 }
 public function confirm($p_array, $p_nothing = 0)
 {
     global $g_parameter, $g_user;
     $r = "";
     bcscale(2);
     extract($p_array);
     $pPeriode = new Periode($this->db);
     if ($this->check_periode() == true) {
         $pPeriode->p_id = $periode;
     } else {
         if (isDate($e_date) != null) {
             $pPeriode->find_periode($e_date);
         } else {
             $pPeriode->p_id = $g_user->get_periode();
         }
     }
     list($l_date_start, $l_date_end) = $pPeriode->get_date_limit();
     $exercice = $pPeriode->get_exercice();
     $r .= '';
     $r .= '<fieldset><legend>Banque, caisse </legend>';
     $r .= '<div id="jrn_name_div">';
     $r .= '<h2 id="jrn_name" style="display:inline">' . $this->get_name() . '</h2>';
     $r .= '</div>';
     $r .= '<TABLE  width="100%">';
     //  Date
     //--
     $r .= "<tr>";
     if ($chdate == 1) {
         $r .= '<td> Date : </td><td>' . $e_date;
     }
     // Periode
     //--
     $r .= "<td>";
     $r .= "Période comptable </td><td>";
     $r .= $l_date_start . ' - ' . $l_date_end;
     $r .= "</td>";
     $r .= "</tr>";
     // Ledger (p_jrn)
     //--
     $r .= '<tr>';
     $r .= '<td> Journal </td>';
     $this->id = $p_jrn;
     $r .= '<td>';
     $r .= h($this->get_name());
     $r .= '</td>';
     $r .= '</tr>';
     //retrieve bank name
     $bk_id = $this->get_bank();
     $fBank = new Fiche($this->db, $bk_id);
     $e_bank_account_label = $this->get_bank_name();
     $filter_year = "  j_tech_per in (select p_id from parm_periode where  p_exercice='" . $exercice . "')";
     $acc_account = new Acc_Account_Ledger($this->db, $fBank->strAttribut(ATTR_DEF_ACCOUNT));
     $asolde = $acc_account->get_solde_detail($filter_year);
     $deb = $asolde['debit'];
     $cred = $asolde['credit'];
     $solde = bcsub($deb, $cred);
     $new_solde = $solde;
     $r .= "<TR><td colspan=\"4\"> Banque ";
     $r .= $e_bank_account_label;
     $r .= "</TABLE>";
     $r .= '</fieldset>';
     $r .= '<div class="myfieldset"><h1 class="legend">Extrait de compte</h1>';
     //--------------------------------------------------
     // Saldo begin end
     //-------------------------------------------------
     $r .= '<table>';
     $r .= '<tr>';
     // Extrait
     //--
     $r .= tr('<td> Numéro d\'extrait</td>' . td(h($e_pj)));
     $r .= '<tr><td >Solde début extrait </td>';
     $r .= '<td style="num">' . nbm($first_sold) . '</td></tr>';
     $r .= '<tr><td>Solde fin extrait </td>';
     $r .= '<td style="num">' . nbm($last_sold) . '</td></tr>';
     $r .= '</table>';
     $r .= '<h1 class="legend">Opérations financières</h1>';
     //--------------------------------------------------
     // financial operation
     //-------------------------------------------------
     $r .= '<TABLE style="width:100%" id="fin_item">';
     $r .= "<TR>";
     if ($chdate == 2) {
         $r .= '<th>Date</th>';
     }
     $r .= "<th style=\"width:auto;text-align:left\" colspan=\"2\">Nom</TH>";
     $r .= "<th style=\"text-align:left\" >Commentaire</TH>";
     $r .= "<th style=\"text-align:right\">Montant</TH>";
     $r .= '<th colspan="2"> Op. Concern&eacute;e(s)</th>';
     /* if we use the AC */
     if ($g_parameter->MY_ANALYTIC != 'nu') {
         $anc = new Anc_Plan($this->db);
         $a_anc = $anc->get_list();
         $x = count($a_anc);
         /* set the width of the col */
         $r .= '<th colspan="' . $x . '">' . _('Compt. Analytique') . '</th>';
         /* add hidden variables pa[] to hold the value of pa_id */
         $r .= Anc_Plan::hidden($a_anc);
     }
     $r .= "</TR>";
     // Parse each " tiers"
     $tot_amount = 0;
     //--------------------------------------------------
     // For each items
     //--------------------------------------------------
     for ($i = 0; $i < $nb_item; $i++) {
         $tiers = isset(${"e_other" . $i}) ? ${"e_other" . $i} : "";
         if (strlen(trim($tiers)) == 0) {
             continue;
         }
         $tiers_label = "";
         $tiers_amount = round(${"e_other{$i}" . "_amount"}, 2);
         $tot_amount = bcadd($tot_amount, $tiers_amount);
         $tiers_comment = h(${"e_other{$i}" . "_comment"});
         // If $tiers has a value
         $fTiers = new Fiche($this->db);
         $fTiers->get_by_qcode($tiers);
         $tiers_label = $fTiers->strAttribut(ATTR_DEF_NAME);
         $r .= "<TR>";
         if ($chdate == 2) {
             $r .= td(${"dateop" . $i});
         }
         $r .= "<td>" . ${'e_other' . $i} . "</TD>";
         // label
         $r .= '<TD style="width:25%;border-bottom:1px dotted grey;">';
         $r .= $fTiers->strAttribut(ATTR_DEF_NAME);
         $r .= '</td>';
         // Comment
         $r .= '<td style="width:40%">' . $tiers_comment . '</td>';
         // amount
         $r .= '<td class="num">' . nbm($tiers_amount) . '</td>';
         // concerned
         $r .= '<td style="text-align:center">';
         if (${"e_concerned" . $i} != '') {
             $jr_internal = $this->db->get_array("select jr_internal from jrn where jr_id in (" . ${"e_concerned" . $i} . ")");
             $comma = "";
             for ($x = 0; $x < count($jr_internal); $x++) {
                 $r .= $comma . HtmlInput::detail_op(${"e_concerned" . $i}, $jr_internal[$x]['jr_internal']);
                 $comma = " , ";
             }
         }
         $r .= '</td>';
         // encode the pa
         if ($g_parameter->MY_ANALYTIC != 'nu' && preg_match("/^[6,7]/", $fTiers->strAttribut(ATTR_DEF_ACCOUNT)) == 1) {
             // show form
             $anc_op = new Anc_Operation($this->db);
             $null = $g_parameter->MY_ANALYTIC == 'op' ? 1 : 0;
             $r .= '<td>';
             $p_mode = 1;
             $p_array['pa_id'] = $a_anc;
             /* op is the operation it contains either a sequence or a jrnx.j_id */
             $r .= HtmlInput::hidden('op[]=', $i);
             $r .= $anc_op->display_form_plan($p_array, $null, $p_mode, $i, $tiers_amount);
             $r .= '</td>';
         }
         $r .= '</TR>';
     }
     $r .= "</TABLE>";
     // saldo
     $r .= '<br>Ancien solde = ' . $solde;
     $new_solde += $tot_amount;
     $r .= '<br>Nouveau solde = ' . $new_solde;
     $r .= '<br>Difference =' . $tot_amount;
     // check for upload piece
     $file = new IFile();
     $r .= "<br>Ajoutez une pi&egrave;ce justificative ";
     $r .= $file->input("pj", "");
     $r .= '</div>';
     //--------------------------------------------------
     // Hidden variables
     //--------------------------------------------------
     $r .= dossier::hidden();
     $r .= HtmlInput::hidden('p_jrn', $this->id);
     $r .= HtmlInput::hidden('nb_item', $nb_item);
     $r .= HtmlInput::hidden('last_sold', $last_sold);
     $r .= HtmlInput::hidden('first_sold', $first_sold);
     $r .= HtmlInput::hidden('e_pj', $e_pj);
     $r .= HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
     $r .= HtmlInput::hidden('e_date', $e_date);
     $mt = microtime(true);
     $r .= HtmlInput::hidden('mt', $mt);
     if (isset($periode)) {
         $r .= HtmlInput::hidden('periode', $periode);
     }
     $r .= dossier::hidden();
     $r .= HtmlInput::hidden('sa', 'n', 'chdate');
     for ($i = 0; $i < $nb_item; $i++) {
         $tiers = isset(${"e_other" . $i}) ? ${"e_other" . $i} : "";
         $r .= HtmlInput::hidden('e_other' . $i, $tiers);
         $r .= HtmlInput::hidden('e_other' . $i, $tiers);
         $r .= HtmlInput::hidden('e_other' . $i . '_comment', ${'e_other' . $i . '_comment'});
         $r .= HtmlInput::hidden('e_other' . $i . '_amount', ${'e_other' . $i . '_amount'});
         $r .= HtmlInput::hidden('e_concerned' . $i, ${'e_concerned' . $i});
         $r .= HtmlInput::hidden('dateop' . $i, ${'dateop' . $i});
         $r .= HtmlInput::hidden('chdate', $chdate);
     }
     return $r;
 }
Example #10
0
if (!defined('ALLOWED')) {
    die('Appel direct ne sont pas permis');
}
require_once NOALYSS_INCLUDE . '/class_periode.php';
/**\file
 * \brief display or save a periode
 * variable received $op, $cn $g_user
 */
$err = 0;
$html = '';
/* we check the security */
switch ($op) {
    case 'input_per':
        $per = new Periode($cn, $_GET['p_id']);
        $per->load();
        $limit = $per->get_date_limit($_GET['p_id']);
        $p_start = new IDate('p_start');
        $p_start->value = $limit['p_start'];
        $p_end = new IDate('p_end');
        $p_end->value = $limit['p_end'];
        $p_exercice = new INum('p_exercice');
        $p_exercice->value = $per->p_exercice;
        $html = '';
        $html .= HtmlInput::anchor_close('mod_periode');
        $html .= h2info(_('Modification période'));
        $html .= '<p> ' . _('Modifier les dates de début et fin de période') . '</p>';
        $html .= '<p class="notice">' . _('Cela pourrait avoir un impact sur les opérations déjà existantes') . '</p>';
        $html .= '<form method="post" onsubmit="return save_periode(this)">';
        $html .= dossier::hidden();
        $html .= '<table>';
        $html .= tr(td(_(' Début période : ')) . td($p_start->input()));
    function confirm($p_array, $p_summary = false)
    {
        global $g_parameter;
        extract($p_array);
        // we don't need to verify if we need only a feedback
        if (!$p_summary) {
            $this->verify($p_array);
        }
        $anc = null;
        // to show a select list for the analytic
        // if analytic is op (optionnel) there is a blank line
        bcscale(4);
        $client = new Fiche($this->db);
        $client->get_by_qcode($e_client, true);
        $client_name = h($client->getName() . ' ' . $client->strAttribut(ATTR_DEF_ADRESS) . ' ' . $client->strAttribut(ATTR_DEF_CP) . ' ' . $client->strAttribut(ATTR_DEF_CITY));
        $lPeriode = new Periode($this->db);
        if ($this->check_periode() == true) {
            $lPeriode->p_id = $period;
        } else {
            $lPeriode->find_periode($e_date);
        }
        $date_limit = $lPeriode->get_date_limit();
        $r = "";
        $r .= '<TABLE>';
        if ($p_summary) {
            $jr_id = $this->db->get_value('select jr_id from jrn where jr_internal=$1', array($this->internal));
            $r .= "<tr>";
            $r .= '<td>';
            $r .= _('Détail opération ');
            $r .= '</td>';
            $r .= '<td>';
            $r .= sprintf('<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a>', $jr_id, dossier::id(), $this->internal);
            $r .= '</td>';
            $r .= "</tr>";
        }
        $r .= '<tr>';
        if (!$p_summary) {
            $r .= '<td>' . _('Numéro Pièce') . '</td><td>' . hb($e_pj) . '</td>';
        } else {
            if (strcmp($this->pj, $e_pj) != 0) {
                $r .= '<td>' . _('Numéro Pièce') . '</td><td>' . hb($this->pj) . '<span class="notice"> ' . _('Attention numéro pièce existante, elle a du être adaptée') . '</span></td>';
            } else {
                $r .= '<td>' . _('Numéro Pièce') . '</td><td>' . hb($this->pj) . '</td>';
            }
        }
        $r .= '</tr>';
        $r .= '<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
        $r .= '</tr>';
        $r .= '<tr>';
        $r .= '<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
        $r .= '</tr>';
        $r .= '<tr>';
        $r .= '<td> ' . _('Période Comptable') . '</td><td> ' . hb($date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
        $r .= '</tr>';
        $r .= '<tr>';
        $r .= '<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . '</td>';
        $r .= '</tr>';
        $r .= '<tr>';
        $r .= '<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
        $r .= '</tr>';
        $r .= '<tr>';
        $r .= '<tr>';
        $r .= '<td> ' . _('Fournisseur') . '</td><td> ' . hb($e_client . ':' . $client_name) . '</td>';
        $r .= '</tr>';
        $r .= '</table>';
        $r .= '<h2>' . _('Détail articles achetés') . '</h2>';
        $r .= '<p class="decale">';
        $r .= '<table class="result" >';
        $r .= '<TR>';
        $r .= "<th>" . _('Code') . "</th>";
        $r .= "<th>" . _('Dénomination') . "</th>";
        $r .= "<th style=\"text-align:right\">" . _('prix') . "</th>";
        $r .= "<th style=\"text-align:right\">" . _('quantité') . "</th>";
        if ($g_parameter->MY_TVA_USE == 'Y') {
            $r .= "<th style=\"text-align:right\">" . _('tva') . "</th>";
            $r .= '<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
            $r .= '<th style="text-align:right">' . _('Montant HTVA') . '</th>';
            $r .= '<th style="text-align:right">' . _('Montant TVAC') . '</th>';
        } else {
            $r .= '<th style="text-align:right">' . _('Montant') . '</th>';
        }
        /* if we use the AC */
        if ($g_parameter->MY_ANALYTIC != 'nu') {
            $anc = new Anc_Plan($this->db);
            $a_anc = $anc->get_list();
            $x = count($a_anc);
            /* set the width of the col */
            $r .= '<th colspan="' . $x . '">' . _('Compt. Analytique') . '</th>';
            /* add hidden variables pa[] to hold the value of pa_id */
            $r .= Anc_Plan::hidden($a_anc);
        }
        $r .= '</tr>';
        $tot_amount = 0.0;
        $tot_tva = 0.0;
        //--
        // For each item
        //--
        for ($i = 0; $i < $nb_item; $i++) {
            $tot_row = 0;
            if (strlen(trim(${"e_march" . $i})) == 0) {
                continue;
            }
            /* retrieve information for card */
            $fiche = new Fiche($this->db);
            $fiche->get_by_qcode(${"e_march" . $i});
            if ($g_parameter->MY_UPDLAB == 'Y') {
                $fiche_name = h(${"e_march" . $i . "_label"});
            } else {
                $fiche_name = $fiche->strAttribut(ATTR_DEF_NAME);
            }
            $amount = bcmul(${"e_march" . $i . "_price"}, ${'e_quant' . $i});
            if ($g_parameter->MY_TVA_USE == 'Y') {
                $idx_tva = ${"e_march" . $i . "_tva_id"};
                $oTva = new Acc_Tva($this->db);
                $oTva->set_parameter('id', $idx_tva);
                $oTva->load();
                $op = new Acc_Compute();
                $op->set_parameter("amount", $amount);
                $op->set_parameter('amount_vat_rate', $oTva->get_parameter('rate'));
                $op->compute_vat();
                $tva_computed = $op->get_parameter('amount_vat');
                //----- if tva_amount is not given we compute the vat ----
                if (strlen(trim(${'e_march' . $i . '_tva_amount'})) == 0) {
                    $tva_item = $op->get_parameter('amount_vat');
                } else {
                    $tva_item = round(${'e_march' . $i . '_tva_amount'}, 2);
                }
                if (isset($tva[$idx_tva])) {
                    $tva[$idx_tva] = bcadd($tva_item, $tva[$idx_tva]);
                } else {
                    $tva[$idx_tva] = $tva_item;
                }
            }
            $tot_amount = round(bcadd($tot_amount, $amount), 2);
            $tot_row = round(bcadd($tot_row, $amount), 2);
            $r .= '<tr>';
            $r .= '<td>';
            $r .= ${"e_march" . $i};
            $r .= '</td>';
            $r .= '<TD style="border-bottom:1px dotted grey;">';
            $r .= $fiche_name;
            $r .= '</td>';
            $r .= '<td class="num">';
            $r .= nbm(${"e_march" . $i . "_price"});
            $r .= '</td>';
            $r .= '<td class="num">';
            $r .= nbm(${"e_quant" . $i});
            $r .= '</td>';
            $both_side = 0;
            if ($g_parameter->MY_TVA_USE == 'Y') {
                $r .= '<td class="num">';
                $r .= $oTva->get_parameter('label');
                $both_side = $oTva->get_parameter("both_side");
                if ($both_side == 0) {
                    $tot_row = bcadd($tot_row, $tva_item);
                    $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
                }
                $r .= '</td>';
                /* warning if tva_computed and given are not the
                   same */
                $css_void_tva = $both_side == 1 ? 'style="text-decoration:line-through"' : '';
                if (bcsub($tva_item, $tva_computed) != 0 && !($tva_item == 0 && $both_side == 1)) {
                    $r .= '<td style="background-color:red" class="num" ' . $css_void_tva . '>';
                    $r .= HtmlInput::infobulle(28);
                    $r .= '<a href="#" class="error" style="display:inline" title="' . _("Attention Différence entre TVA calculée et donnée") . '">' . nbm($tva_item) . '<a>';
                } else {
                    $r .= '<td  class="num" ' . $css_void_tva . '>';
                    $r .= nbm($tva_item);
                }
                $r .= '</td>';
                $r .= '<td class="num"> ';
                $r .= nbm(round($amount, 2));
                $r .= '</td>';
            }
            $r .= '<td class="num">';
            $r .= nbm(round($tot_row, 2));
            $r .= '</td>';
            // encode the pa
            if ($g_parameter->MY_ANALYTIC != 'nu') {
                // show form
                $anc_op = new Anc_Operation($this->db);
                $null = $g_parameter->MY_ANALYTIC == 'op' ? 1 : 0;
                $r .= '<td>';
                $p_mode = $p_summary == false ? 1 : 0;
                $p_array['pa_id'] = $a_anc;
                /* op is the operation it contains either a sequence or a jrnx.j_id */
                $r .= HtmlInput::hidden('op[]=', $i);
                $r .= $anc_op->display_form_plan($p_array, $null, $p_mode, $i, $amount);
                $r .= '</td>';
            }
            $r .= '</tr>';
        }
        // Add the sum
        $decalage = $g_parameter->MY_TVA_USE == 'Y' ? '<td></td><td></td><td></td><td></td>' : '<td></td>';
        $tot = round(bcadd($tot_amount, $tot_tva), 2);
        $tot_tva = nbm($tot_tva);
        $tot = nbm($tot);
        $str_tot = _('Totaux');
        $tot_amount = nbm($tot_amount);
        $r .= <<<EOF
<tr class="highlight">
    {$decalage}            
     <td>
                {$str_tot}
     </td>
    <td class="num">
        {$tot_tva}
    </td>
    <td class="num">
        {$tot_amount}
    </td>
    <td class="num">
        {$tot}
    </td>
EOF;
        $r .= '</table>';
        $r .= '</p>';
        if ($g_parameter->MY_ANALYTIC != 'nu' && !$p_summary) {
            // use of AA
            $r .= '<input type="button" class="button" value="' . _('Vérifiez imputation analytique') . '" onClick="verify_ca(\'\');">';
        }
        $r .= !$p_summary ? '<div id="total_div_id" >' : '<div>';
        $r .= '<h2>Totaux</h2>';
        /* use VAT */
        if ($g_parameter->MY_TVA_USE == 'Y') {
            $r .= '<table>';
            $r .= '<tr><td>Total HTVA</td>';
            $r .= td(hb($tot_amount), 'class="num"');
            foreach ($tva as $i => $value) {
                $oTva->set_parameter('id', $i);
                $oTva->load();
                $r .= '<tr><td>  TVA ' . $oTva->get_parameter('label') . '</td>';
                $r .= td(hb(nbm($tva[$i])), 'class="num"');
            }
            $r .= '<tr>' . td(_('Total TVA')) . td(hb($tot_tva), 'class="num"');
            $r .= '<tr>' . td(_('Total TVAC')) . td(hb($tot), 'class="num"');
            $r .= '</table>';
        } else {
            $r .= '<br>Total ' . hb($tot);
        }
        $r .= '</div>';
        /*  Add hidden */
        $r .= HtmlInput::hidden('e_client', $e_client);
        $r .= HtmlInput::hidden('nb_item', $nb_item);
        $r .= HtmlInput::hidden('p_jrn', $p_jrn);
        if (isset($period)) {
            $r .= HtmlInput::hidden('period', $period);
        }
        $r .= HtmlInput::hidden('e_comm', $e_comm);
        $r .= HtmlInput::hidden('e_date', $e_date);
        $r .= HtmlInput::hidden('e_ech', $e_ech);
        $r .= HtmlInput::hidden('jrn_type', $jrn_type);
        $r .= HtmlInput::hidden('e_pj', $e_pj);
        $r .= HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
        $mt = microtime(true);
        $r .= HtmlInput::hidden('mt', $mt);
        $e_mp = isset($e_mp) ? $e_mp : 0;
        $r .= HtmlInput::hidden('e_mp', $e_mp);
        /* Paid by */
        /* if the paymethod is not 0 and if a quick code is given */
        for ($i = 0; $i < $nb_item; $i++) {
            $r .= HtmlInput::hidden("e_march" . $i, ${"e_march" . $i});
            if (isset(${"e_march" . $i . "_label"})) {
                $r .= HtmlInput::hidden("e_march" . $i . "_label", ${"e_march" . $i . "_label"});
            }
            $r .= HtmlInput::hidden("e_march" . $i . "_price", ${"e_march" . $i . "_price"});
            if ($g_parameter->MY_TVA_USE == 'Y') {
                $r .= HtmlInput::hidden("e_march" . $i . "_tva_id", ${"e_march" . $i . "_tva_id"});
                $r .= HtmlInput::hidden('e_march' . $i . '_tva_amount', ${'e_march' . $i . '_tva_amount'});
            }
            $r .= HtmlInput::hidden("e_quant" . $i, ${"e_quant" . $i});
        }
        /**
         * 
         */
        if ($e_mp != 0 && strlen(trim(${'e_mp_qcode_' . $e_mp})) != 0) {
            $r .= HtmlInput::hidden('e_mp_qcode_' . $e_mp, ${'e_mp_qcode_' . $e_mp});
            $r .= HtmlInput::hidden('acompte', $acompte);
            $r .= HtmlInput::hidden('e_comm_paiement', $e_comm_paiement);
            /* needed for generating a invoice */
            $r .= HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
            $fname = new Fiche($this->db);
            $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
            $r .= '<h2>' . _("Payé par") . " " . ${'e_mp_qcode_' . $e_mp} . " " . $fname->getName() . '</h2> ' . '<p class="decale">' . _('Déduction acompte ') . h($acompte) . '</p>' . _('Libellé :') . h($e_comm_paiement);
            $r .= '<br>';
            $r .= '<br>';
        }
        // check for upload piece
        return $r;
    }