Example #1
0
global $g_user, $g_failed;
/**
 * Show first the form
 */
/* category */
$categorie = new ISelect('cat');
$categorie->value = $cn->make_array('select fd_id,fd_label from fiche_def order by fd_label');
$categorie->selected = isset($_GET['cat']) ? $_GET['cat'] : 0;
$str_categorie = $categorie->input();
$icall = new ICheckBox("allcard", 1);
$icall->selected = isset($_GET['allcard']) ? 1 : 0;
$str_icall = $icall->input();
/* periode */
$exercice = $g_user->get_exercice();
$iperiode = new Periode($cn);
list($first, $last) = $iperiode->get_limit($exercice);
$periode_start = new IDate('start');
$periode_end = new IDate('end');
$periode_start->value = isset($_GET['start']) ? $_GET['start'] : $first->first_day();
$periode_end->value = isset($_GET['end']) ? $_GET['end'] : $last->last_day();
$str_start = $periode_start->input();
$str_end = $periode_end->input();
/* histo ou summary */
$histo = new ISelect('histo');
$histo->value = array(array('value' => -1, 'label' => _('Liste')), array('value' => 0, 'label' => _('Historique')), array('value' => 1, 'label' => _('Historique Lettré')), array('value' => 6, 'label' => _('Historique Lettré et montants différents')), array('value' => 2, 'label' => _('Historique non Lettré')), array('value' => 3, 'label' => _('Résumé')), array('value' => 4, 'label' => _('Balance')), array('value' => 6, 'label' => _('Balance âgée')), array('value' => 7, 'label' => _('Balance âgée en-cours')), array('value' => 5, 'label' => _('Balance non soldée')));
$histo->javascript = 'onchange="if (this.value==3 || this.value==-1) {
                   g("trstart").style.display="none";g("trend").style.display="none";g("allcard").style.display="none";}
                   else  {g("trstart").style.display="";g("trend").style.display="";g("allcard").style.display="";}"';
$histo->selected = isset($_GET['histo']) ? $_GET['histo'] : -1;
$str_histo = $histo->input();
echo '<div class="content">';
Example #2
0
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with NOALYSS; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
// Copyright Author Dany De Bontridder danydb@aevalys.eu
/**
 * @file
 * @brief
 *
 */
if (!defined('ALLOWED')) {
    die('Appel direct ne sont pas permis');
}
global $g_user, $cn, $g_parameter;
require_once NOALYSS_INCLUDE . '/class_stock.php';
require_once NOALYSS_INCLUDE . '/class_periode.php';
$stock = new Stock($cn);
$array = $_GET;
if (!isset($array['wdate_start']) || !isset($array['wdate_end'])) {
    // Date start / end
    $exercice = $g_user->get_exercice();
    $periode = new Periode($cn);
    list($periode_start, $periode_end) = $periode->get_limit($exercice);
    $array['wdate_start'] = $periode_start->first_day();
    $array['wdate_end'] = $periode_end->last_day();
}
$stock->history($array);
// Show the jrn and date
//-----------------------------------------------------
require_once NOALYSS_INCLUDE . '/class_database.php';
global $g_user;
//-----------------------------------------------------
// Form
//-----------------------------------------------------
echo '<div class="content">';
echo '<FORM action="?" METHOD="GET">';
echo HtmlInput::hidden('ac', $_REQUEST['ac']);
echo HtmlInput::hidden('type', 'gl_comptes');
echo dossier::hidden();
echo '<TABLE><TR>';
$cn = new Database(dossier::id());
$periode = new Periode($cn);
$a = $periode->get_limit($g_user->get_exercice());
// $a is an array
$first_day = $a[0]->first_day();
$last_day = $a[1]->last_day();
// filter on period
$date_from = new IDate('from_periode');
$date_to = new IDate('to_periode');
$year = $g_user->get_exercice();
$date_from->value = isset($_REQUEST['from_periode']) && isDate($_REQUEST['from_periode']) != 0 ? $_REQUEST['from_periode'] : $first_day;
$date_to->value = isset($_REQUEST['to_periode']) && isDate($_REQUEST['to_periode']) != 0 ? $_REQUEST['to_periode'] : $last_day;
echo td(_('Depuis') . $date_from->input());
echo td(_('Jusque ') . $date_to->input());
$letter = new ICheckbox('letter');
$letter->selected = isset($_REQUEST['letter']) ? true : false;
$from_poste = new IPoste('from_poste');
$from_poste->value = HtmlInput::default_value('from_poste', '', $_REQUEST);
Example #4
0
 function search_box($p_array)
 {
     // Declaration
     global $g_user;
     $wrepo = HtmlInput::select_stock($this->cn, "wrepo", 'R');
     $wrepo->value[] = array('value' => -1, 'label' => 'Tous les dépôts');
     $wdate_start = new IDate('wdate_start');
     $wdate_end = new IDate('wdate_end');
     $wamount_start = new INum('wamount_start');
     $wamount_end = new INum('wamount_end');
     $wcard = new ICard('wcard');
     $wcode_stock = new ICard('wcode_stock');
     $wdirection = new ISelect("wdirection");
     // value
     $wrepo->selected = HtmlInput::default_value("wrepo", -1, $p_array);
     // Date start / end
     $exercice = $g_user->get_exercice();
     $periode = new Periode($this->cn);
     list($periode_start, $periode_end) = $periode->get_limit($exercice);
     $wdate_start->value = HtmlInput::default_value("wdate_start", $periode_start->first_day(), $p_array);
     $wdate_end->value = HtmlInput::default_value("wdate_end", $periode_end->last_day(), $p_array);
     //amounts
     $wamount_start->value = HtmlInput::default_value("wamount_start", 0, $p_array);
     $wamount_end->value = HtmlInput::default_value("wamount_end", 0, $p_array);
     //Card
     $wcard->extra = "all";
     $wcard->set_attribute("typecard", "all");
     $wcard->value = HtmlInput::default_value("wcard", "", $p_array);
     //Card stock
     $wcode_stock->extra = " [sql] fd_id=500000 ";
     $wcode_stock->set_attribute("typecard", "[sql] fd_id=500000");
     $wcode_stock->value = HtmlInput::default_value("wcard", "", $p_array);
     // Repository
     $wcode_stock->value = HtmlInput::default_value("wcode_stock", "", $p_array);
     //Direction
     $wdirection->value = array(array('value' => "-1", 'label' => "Tout"), array('value' => "c", 'label' => "OUT"), array('value' => "d", 'label' => "IN"));
     $wdirection->selected = HtmlInput::default_value("wdirection", "-1", $p_array);
     require_once NOALYSS_INCLUDE . '/template/stock_histo_search.php';
 }
Example #5
0
$deb = $cn->get_value("select sum (j_montant) from jrnx where j_debit='t' {$sql_year} ");
$cred = $cn->get_value("select sum (j_montant) from jrnx where j_debit='f' {$sql_year} ");
if ($cred == $deb) {
    $result = $g_succeed;
} else {
    $result = $g_failed;
}
$class = $ix % 2 == 0 ? 'odd' : "even";
print tr(td(_('Grand livre')) . td(nbm($deb), ' class="num"') . td(nbm($cred), ' class="num"') . td(nbm($result), ' class="num"') . td($result), "class=\"{$class}\"");
echo '</table>';
echo '</div>';
echo '<hr>';
echo '<div class="myfieldset"><h1 class="legend">' . _('Vérification des comptes') . '</h1>';
$bilan = new Acc_Bilan($cn);
$periode = new Periode($cn);
list($start_periode, $end_periode) = $periode->get_limit($exercice);
$bilan->from = $start_periode->p_id;
$bilan->to = $end_periode->p_id;
$bilan->verify();
echo '</div>';
?>
<hr>
<div class="myfieldset">
    <h1 class="legend">
        <?php 
echo _("Vérification des fiches") . '</legend>';
?>
    </h1>
    <h2>
        <?php 
echo _('Fiches ayant changé de poste comptable');
Example #6
0
 /**
  * @brief return the first date and the last date of the current exercice for the current user
  * @return and array ([0] => start_date,[1] => end_date)
  */
 function get_limit_current_exercice()
 {
     $current_exercice = $this->get_exercice();
     $periode = new Periode($this->db);
     list($per_start, $per_end) = $periode->get_limit($current_exercice);
     $start = $per_start->first_day();
     $end = $per_end->last_day();
     return array($start, $end);
 }
 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;
 }
Example #8
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;
 }
Example #9
0
require_once NOALYSS_INCLUDE . '/class_dossier.php';
require_once NOALYSS_INCLUDE . '/class_database.php';
require_once NOALYSS_INCLUDE . '/class_user.php';
require_once NOALYSS_INCLUDE . '/class_periode.php';
html_page_start($_SESSION['g_theme']);
echo '<div style="float:left;">';
global $g_user;
if (basename($_GET['ajax']) == 'ajax_history.php') {
    $href = dossier::get();
    $cn = new Database(dossier::id());
    /* current year  */
    $g_user = new User($cn);
    $exercice = $g_user->get_exercice();
    /* get date limit */
    $periode = new Periode($cn);
    $limit = $periode->get_limit($exercice);
    $from_periode = 'from_periode=' . format_date($limit[0]->p_start);
    $to_periode = 'to_periode=' . format_date($limit[1]->p_end);
    if (isset($_GET['ex'])) {
        if ($exercice > $_GET['ex']) {
            $limit_periode = $periode->get_limit($_GET['ex']);
            $from_periode = 'from_periode=' . format_date($limit_periode[0]->p_start);
        } else {
            $limit_periode = $periode->get_limit($_GET['ex']);
            $to_periode = 'to_periode=' . format_date($limit_periode[1]->p_end);
        }
    }
    if (isset($_GET['pcm_val'])) {
        $href_csv = "export.php?" . $href . '&poste_id=' . $_GET['pcm_val'] . '&ople=0&type=poste&' . $from_periode . '&' . $to_periode . "&act=CSV:postedetail";
        $href_pdf = "export.php?" . $href . '&poste_id=' . $_GET['pcm_val'] . '&ople=0&type=poste&' . $from_periode . '&' . $to_periode . "&act=PDF:postedetail";
    } else {
Example #10
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;
     }
 }
}
require_once NOALYSS_INCLUDE . '/class_lettering.php';
global $g_user;
echo '<div class="content">';
echo '<div id="search">';
echo '<FORM METHOD="GET">';
echo dossier::hidden();
echo HtmlInput::hidden('ac', $_REQUEST['ac']);
echo HtmlInput::hidden('sb', $_REQUEST['sb']);
echo HtmlInput::hidden('sc', $_REQUEST['sc']);
echo HtmlInput::hidden('f_id', $_REQUEST['f_id']);
echo '<table width="50%">';
// limit of the year
$exercice = $g_user->get_exercice();
$periode = new Periode($cn);
list($first_per, $last_per) = $periode->get_limit($exercice);
$start = new IDate('start');
$start->value = isset($_GET['start']) ? $_GET['start'] : $first_per->first_day();
$r = td(_('Date début'));
$r .= td($start->input());
echo tr($r);
$end = new IDate('end');
$end->value = isset($_GET['end']) ? $_GET['end'] : $last_per->last_day();
$r = td(_('Date fin'));
$r .= td($end->input());
echo tr($r);
// type of lettering : all, lettered, not lettered
$sel = new ISelect('type_let');
$sel->value = array(array('value' => 0, 'label' => _('Toutes opérations')), array('value' => 1, 'label' => _('Opérations lettrées')), array('value' => 2, 'label' => _('Opérations NON lettrées')));
if (isset($_GET['type_let'])) {
    $sel->selected = $_GET['type_let'];
Example #12
0
        ob_end_clean();
    }
}
///////////////////////////////////////////////////////////////////////////
// for an account
///////////////////////////////////////////////////////////////////////////
if (isset($_REQUEST['pcm_val'])) {
    $poste = new Acc_Account_Ledger($cn, $_REQUEST['pcm_val']);
    $year = $g_user->get_exercice();
    if ($year == 0) {
        $html = _("erreur aucune période par défaut, allez dans préférence pour en choisir une");
    } else {
        $exercice = new Exercice($cn);
        $old = '';
        $per = new Periode($cn);
        $limit_periode = $per->get_limit($year);
        $array['from_periode'] = $limit_periode[0]->first_day();
        $array['to_periode'] = $limit_periode[1]->last_day();
        if (isset($_GET['ex'])) {
            $limit_periode = $per->get_limit($_GET['ex']);
            if ($_GET['ex'] < $year) {
                $array['from_periode'] = $limit_periode[0]->first_day();
            } else {
                $array['to_periode'] = $limit_periode[1]->last_day();
            }
        }
        /*
         * Add button to select another year
         */
        if ($exercice->count() > 1) {
            $default = isset($_GET['ex']) ? $_GET['ex'] : $year;
 /**
  *@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;
 }
Example #14
0
 function Summary($p_search = "", $p_action = "", $p_sql = "", $p_amount = false)
 {
     global $g_user;
     $bank = new Acc_Parm_Code($this->cn, 'BANQUE');
     $cash = new Acc_Parm_Code($this->cn, 'CAISSE');
     $cc = new Acc_Parm_Code($this->cn, 'COMPTE_COURANT');
     bcscale(4);
     $gDossier = dossier::id();
     $p_search = sql_string($p_search);
     $script = $_SERVER['PHP_SELF'];
     // Creation of the nav bar
     // Get the max numberRow
     $filter_amount = '';
     global $g_user;
     $filter_year = "  j_tech_per in (select p_id from parm_periode " . "where p_exercice='" . $g_user->get_exercice() . "')";
     if ($p_amount) {
         $filter_amount = ' and f_id in (select f_id from jrnx where  ' . $filter_year . ')';
     }
     $all_tiers = $this->count_by_modele($this->fiche_def_ref, "", $p_sql . $filter_amount);
     // Get offset and page variable
     $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0;
     $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
     $bar = navigation_bar($offset, $all_tiers, $_SESSION['g_pagesize'], $page);
     // set a filter ?
     $search = $p_sql;
     $exercice = $g_user->get_exercice();
     $tPeriode = new Periode($this->cn);
     list($max, $min) = $tPeriode->get_limit($exercice);
     if (trim($p_search) != "") {
         $search .= " and f_id in\n                     (select distinct f_id from fiche_detail\n                     where\n                     ad_id in (1,32,30,23,18,13) and ad_value ~* '{$p_search}')";
     }
     // Get The result Array
     $step_tiers = $this->get_by_category($offset, $search . $filter_amount, 'name');
     if ($all_tiers == 0 || count($step_tiers) == 0) {
         return "";
     }
     $r = "";
     $r .= _("Filtre rapide ") . HtmlInput::filter_table("tiers_tb", '0,1,2', 1);
     $r .= $bar;
     $r .= '<table  id="tiers_tb" class="sortable"  style="width:90%;margin-left:5%">
         <TR >
         <TH>' . _('Quick Code') . HtmlInput::infobulle(17) . '</TH>' . '<th>' . _('Poste comptable') . '</th>' . '<th  class="sorttable_sorted_reverse">' . _('Nom') . '<span id="sorttable_sortrevind">&nbsp;&blacktriangle;</span>' . '</th>
         <th>' . _('Adresse') . '</th>
         <th style="text-align:right">' . _('Total débit') . '</th>
         <th style="text-align:right">' . _('Total crédit') . '</th>
         <th style="text-align:right">' . _('Solde') . '</th>';
     $r .= '</TR>';
     if (sizeof($step_tiers) == 0) {
         return $r;
     }
     $i = 0;
     $deb = 0;
     $cred = 0;
     foreach ($step_tiers as $tiers) {
         $i++;
         /* Filter on the default year */
         $amount = $tiers->get_solde_detail($filter_year);
         /* skip the tiers without operation */
         if ($p_amount && $amount['debit'] == 0 && $amount['credit'] == 0 && $amount['solde'] == 0) {
             continue;
         }
         $odd = "";
         $odd = $i % 2 == 0 ? ' odd ' : ' even ';
         $accounting = $tiers->strAttribut(ATTR_DEF_ACCOUNT);
         if ($p_action == 'bank' && $amount['debit'] < $amount['credit']) {
             if (strpos($accounting, $bank->p_value) === 0 || strpos($accounting, $cash->p_value) === 0 || strpos($accounting, $cc->p_value) === 0) {
                 //put in red if c>d
                 $odd .= " notice ";
             }
         }
         $odd = ' class="' . $odd . '"';
         $r .= "<TR {$odd}>";
         $url_detail = $script . '?' . http_build_query(array('sb' => 'detail', 'sc' => 'sv', 'ac' => $_REQUEST['ac'], 'f_id' => $tiers->id, 'gDossier' => $gDossier));
         $e = sprintf('<A HREF="%s" title="Détail" class="line"> ', $url_detail);
         $r .= "<TD> {$e}" . $tiers->strAttribut(ATTR_DEF_QUICKCODE) . "</A></TD>";
         $r .= "<TD> {$e}" . $accounting . "</TD>";
         $r .= "<TD>" . h($tiers->strAttribut(ATTR_DEF_NAME)) . "</TD>";
         $r .= "<TD>" . h($tiers->strAttribut(ATTR_DEF_ADRESS) . " " . $tiers->strAttribut(ATTR_DEF_CP) . " " . $tiers->strAttribut(ATTR_DEF_PAYS)) . "</TD>";
         $str_deb = $amount['debit'] == 0 ? 0 : nbm($amount['debit']);
         $str_cred = $amount['credit'] == 0 ? 0 : nbm($amount['credit']);
         $str_solde = nbm($amount['solde']);
         $r .= '<TD sorttable_customkey="' . $amount['debit'] . '" align="right"> ' . $str_deb . '</TD>';
         $r .= '<TD sorttable_customkey="' . $amount['credit'] . '" align="right"> ' . $str_cred . '</TD>';
         $side = $amount['debit'] > $amount['credit'] ? 'D' : 'C';
         $side = $amount['debit'] == $amount['credit'] ? '=' : $side;
         $red = "";
         if ($p_action == 'customer' && $amount['debit'] < $amount['credit']) {
             //put in red if d>c
             $red = " notice ";
         }
         if ($p_action == 'supplier' && $amount['debit'] > $amount['credit']) {
             //put in red if c>d
             $red = " notice ";
         }
         $r .= '<TD class="' . $red . '" sorttable_customkey="' . $amount['solde'] . '" align="right"> ' . $str_solde . "{$side} </TD>";
         $deb = bcadd($deb, $amount['debit']);
         $cred = bcadd($cred, $amount['credit']);
         $r .= "</TR>";
     }
     $r .= "<tfoot >";
     $solde = abs(bcsub($deb, $cred));
     $side = $deb > $cred ? 'Débit' : 'Crédit';
     $r .= '<tr class="highlight">';
     $r .= td("") . td("") . td("") . td("Totaux") . td(nbm($deb), 'class="num"') . td(nbm($cred), 'class="num"') . td(" {$side} " . nbm($solde), 'class="num"');
     $r .= '</tr>';
     $r .= "</tfoot>";
     $r .= "</TABLE>";
     $r .= $bar;
     return $r;
 }