예제 #1
0
 /**
  * @covers Acc_Account::count
  * @todo   Implement testCount().
  */
 public function testCount()
 {
     $this->assertEquals($this->object->count('550'), 1);
     $this->assertEquals($this->object->count('500'), 0);
 }
예제 #2
0
}
$ctl = 'ok';
extract($_GET);
//----------------------------------------------------------------------
// Modification
//----------------------------------------------------------------------
$message = _("opération réussie");
if ($action == "update" && $acc_delete == 0) {
    // Check if the data are correct
    try {
        $p_val = trim($p_valu);
        $p_lib = trim($p_libu);
        $p_parent = trim($p_parentu);
        $old_line = trim($p_oldu);
        $p_type = htmlentities($p_typeu);
        $acc = new Acc_Account($cn);
        $acc->set_parameter('libelle', $p_lib);
        $acc->set_parameter('value', $p_val);
        $acc->set_parameter('parent', $p_parent);
        $acc->set_parameter('type', $p_type);
        $acc->check();
    } catch (Exception $e) {
        $message = _("Valeurs invalides, pas de changement") . " \n " . $e->getMessage();
        $ctl = 'nok';
    }
    if (strlen($p_val) != 0 && strlen($p_lib) != 0 && strlen($old_line) != 0) {
        if (strlen($p_val) == 1) {
            $p_parent = 0;
        } else {
            if (strlen($p_parent) == 0) {
                $p_parent = substr($p_val, 0, strlen($p_val) - 1);
예제 #3
0
 function get_row($p_from_periode, $p_to_periode, $p_previous_exc = 0)
 {
     global $g_user;
     // filter on requested periode
     $per_sql = sql_filter_per($this->db, $p_from_periode, $p_to_periode, 'p_id', 'j_tech_per');
     $and = "";
     $jrn = "";
     $from_poste = "";
     $to_poste = "";
     /* if several ledgers are asked then we filter here  */
     if ($this->jrn !== null) {
         /**
          *@file
          *@bug the get_ledger here is not valid and useless we just need a list of the 
          * asked ledgers
          */
         $jrn = "  j_jrn_def in (";
         $comma = '';
         for ($e = 0; $e < count($this->jrn); $e++) {
             $jrn .= $comma . $this->jrn[$e];
             $comma = ',';
         }
         $jrn .= ')';
         $and = " and ";
     }
     if (strlen(trim($this->from_poste)) != 0 && $this->from_poste != -1) {
         $from_poste = " {$and} j_poste::text >= '" . $this->from_poste . "'";
         $and = " and ";
     }
     if (strlen(trim($this->to_poste)) != 0 && $this->to_poste != -1) {
         $to_poste = " {$and} j_poste::text <= '" . $this->to_poste . "'";
         $and = " and ";
     }
     $filter_sql = $g_user->get_ledger_sql('ALL', 3);
     switch ($p_previous_exc) {
         case 0:
             // build query
             $sql = "select j_poste as poste,sum(deb) as sum_deb, sum(cred) as sum_cred from\n                     ( select j_poste,\n                     case when j_debit='t' then j_montant else 0 end as deb,\n                     case when j_debit='f' then j_montant else 0 end as cred\n                     from jrnx join tmp_pcmn on (j_poste=pcm_val)\n                     left join parm_periode on (j_tech_per = p_id)\n                     join jrn_def on (j_jrn_def=jrn_def_id)\n                     where\n                     {$jrn} {$from_poste} {$to_poste}\n                     {$and} {$filter_sql}\n                     and\n                     {$per_sql} ) as m group by 1 order by 1";
             break;
         case 1:
             /*
              * retrieve balance previous exercice
              */
             $periode = new Periode($this->db);
             $previous_exc = $periode->get_exercice($p_from_periode) - 1;
             try {
                 list($previous_start, $previous_end) = $periode->get_limit($previous_exc);
                 $per_sql_previous = sql_filter_per($this->db, $previous_start->p_id, $previous_end->p_id, 'p_id', 'j_tech_per');
                 $sql = "\n                            with m as \n                                ( select j_poste,sum(deb) as sdeb,sum(cred) as scred\n                                from \n                                (select j_poste, \n                                    case when j_debit='t' then j_montant else 0 end as deb, \n                                    case when j_debit='f' then j_montant else 0 end as cred \n                                    from jrnx \n                                    join tmp_pcmn on (j_poste=pcm_val) \n                                    left join parm_periode on (j_tech_per = p_id) \n                                    join jrn_def on (j_jrn_def=jrn_def_id) \n                                    where\n                                                             {$jrn} {$from_poste} {$to_poste}\n                                    {$and} {$filter_sql} and {$per_sql}\n                                    ) as sub_m group by j_poste order by j_poste ) , \n                            p as ( select j_poste,sum(deb) as sdeb,sum(cred) as scred \n                                from \n                                    (select j_poste, \n                                        case when j_debit='t' then j_montant else 0 end as deb, \n                                        case when j_debit='f' then j_montant else 0 end as cred \n                                        from jrnx join tmp_pcmn on (j_poste=pcm_val) \n                                        left join parm_periode on (j_tech_per = p_id) \n                                        join jrn_def on (j_jrn_def=jrn_def_id) \n                                        where \n                                       {$jrn} {$from_poste} {$to_poste}\n                                    {$and} {$filter_sql} and {$per_sql_previous})  as sub_p group by j_poste order by j_poste)\n                            select coalesce(m.j_poste,p.j_poste) as poste\n                                                                ,coalesce(m.sdeb,0) as sum_deb\n                                                                , coalesce(m.scred,0) as sum_cred \n                                                                ,coalesce(p.sdeb,0) as sum_deb_previous\n                                                                , coalesce(p.scred,0) as sum_cred_previous from m full join p on (p.j_poste=m.j_poste)\n                                             order by poste";
             } catch (Exception $exc) {
                 $p_previous_exc = 0;
                 /*
                  * no previous exercice
                  */
                 $sql = "select upper(j_poste::text) as poste,sum(deb) as sum_deb, sum(cred) as sum_cred from\n                     ( select j_poste,\n                     case when j_debit='t' then j_montant else 0 end as deb,\n                     case when j_debit='f' then j_montant else 0 end as cred\n                     from jrnx join tmp_pcmn on (j_poste=pcm_val)\n                     left join parm_periode on (j_tech_per = p_id)\n                     join jrn_def on (j_jrn_def=jrn_def_id)\n                     where\n                     {$jrn} {$from_poste} {$to_poste}\n                     {$and} {$filter_sql}\n                     and\n                     {$per_sql} ) as m group by poste order by poste";
             }
             break;
     }
     $cn = clone $this->db;
     $Res = $this->db->exec_sql($sql);
     $tot_cred = 0.0;
     $tot_deb = 0.0;
     $tot_deb_saldo = 0.0;
     $tot_cred_saldo = 0.0;
     $tot_cred_previous = 0.0;
     $tot_deb_previous = 0.0;
     $tot_deb_saldo_previous = 0.0;
     $tot_cred_saldo_previous = 0.0;
     $M = $this->db->size();
     // Load the array
     for ($i = 0; $i < $M; $i++) {
         $r = $this->db->fetch($i);
         $poste = new Acc_Account($cn, $r['poste']);
         $a['poste'] = $r['poste'];
         $a['label'] = mb_substr($poste->get_lib(), 0, 40);
         $a['sum_deb'] = round($r['sum_deb'], 2);
         $a['sum_cred'] = round($r['sum_cred'], 2);
         $a['solde_deb'] = round($a['sum_deb'] >= $a['sum_cred'] ? $a['sum_deb'] - $a['sum_cred'] : 0, 2);
         $a['solde_cred'] = round($a['sum_deb'] <= $a['sum_cred'] ? $a['sum_cred'] - $a['sum_deb'] : 0, 2);
         if ($p_previous_exc == 1) {
             $a['sum_deb_previous'] = round($r['sum_deb_previous'], 2);
             $a['sum_cred_previous'] = round($r['sum_cred_previous'], 2);
             $a['solde_deb_previous'] = round($a['sum_deb_previous'] >= $a['sum_cred_previous'] ? $a['sum_deb_previous'] - $a['sum_cred_previous'] : 0, 2);
             $a['solde_cred_previous'] = round($a['sum_deb_previous'] <= $a['sum_cred_previous'] ? $a['sum_cred_previous'] - $a['sum_deb_previous'] : 0, 2);
             $tot_cred_previous += $a['sum_cred_previous'];
             $tot_deb_previous += $a['sum_deb_previous'];
             $tot_deb_saldo_previous += $a['solde_deb_previous'];
             $tot_cred_saldo_previous += $a['solde_cred_previous'];
         }
         if ($p_previous_exc == 0 && $this->unsold == true && $a['solde_cred'] == 0 && $a['solde_deb'] == 0) {
             continue;
         }
         if ($p_previous_exc == 1 && $this->unsold == true && $a['solde_cred'] == 0 && $a['solde_deb'] == 0 && $a['solde_cred_previous'] == 0 && $a['solde_deb_previous'] == 0) {
             continue;
         }
         $array[$i] = $a;
         $tot_cred += $a['sum_cred'];
         $tot_deb += $a['sum_deb'];
         $tot_deb_saldo += $a['solde_deb'];
         $tot_cred_saldo += $a['solde_cred'];
     }
     //for i
     // Add the saldo
     $i += 1;
     $a['poste'] = "";
     $a['label'] = "Totaux ";
     $a['sum_deb'] = $tot_deb;
     $a['sum_cred'] = $tot_cred;
     $a['solde_deb'] = $tot_deb_saldo;
     $a['solde_cred'] = $tot_cred_saldo;
     if ($p_previous_exc == 1) {
         $a['sum_deb_previous'] = $tot_deb_previous;
         $a['sum_cred_previous'] = $tot_cred_previous;
         $a['solde_deb_previous'] = $tot_deb_saldo_previous;
         $a['solde_cred_previous'] = $tot_cred_saldo_previous;
     }
     $array[$i] = $a;
     $this->row = $array;
     return $array;
 }
예제 #4
0
 /**
  * @brief Show the form to encode your operation
  * @param$p_array if you correct or use a predef operation (default = null)
  * @param$p_readonly 1 for readonly 0 for writable (default 0)
  *@exception if ledger not found
  * \return a string containing the form
  */
 function input($p_array = null, $p_readonly = 0)
 {
     global $g_parameter, $g_user;
     $this->nb = $this->get_min_row();
     if ($p_readonly == 1) {
         return $this->confirm($p_array);
     }
     if ($p_array != null) {
         extract($p_array);
     }
     $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_row("quick_item");';
     $ret = "";
     if ($g_user->check_action(FICADD) == 1) {
         /* Add button */
         $f_add_button = new IButton('add_card');
         $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_button->input();
     }
     $wLedger = $this->select_ledger('ODS', 2);
     if ($wLedger == null) {
         throw new Exception(_('Pas de journal disponible'));
     }
     $wLedger->javascript = "onChange='update_name();update_predef(\"ods\",\"t\",\"" . $_REQUEST['ac'] . "\");{$add_js}'";
     $label = " Journal " . HtmlInput::infobulle(2);
     $ret .= $label . $wLedger->input();
     // Load the javascript
     //
     $ret .= "<table>";
     $ret .= '<tr ><td colspan="2" style="width:auto">';
     $wDate = new IDate('e_date');
     $wDate->readonly = $p_readonly;
     $e_date = isset($e_date) && trim($e_date) != '' ? $e_date : '';
     $wDate->value = $e_date;
     $ret .= _("Date") . ' : ' . $wDate->input();
     $ret .= '</td>';
     /* insert periode if needed */
     // 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) {
                 echo _("Aucune période ouverte");
                 exit;
             }
         }
         $label = HtmlInput::infobulle(3);
         $f_periode = _("Période comptable") . " {$label} " . $l_form_per;
         $ret .= td($f_periode);
     }
     $wPJ = new IText('e_pj');
     $wPJ->readonly = false;
     $wPJ->size = 10;
     /* suggest PJ ? */
     $default_pj = '';
     if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
         $default_pj = $this->guess_pj();
     }
     $wPJ->value = isset($e_pj) ? $e_pj : $default_pj;
     $ret .= '</tr>';
     $ret .= '<tr >';
     $ret .= '<td colspan="2" style="width:auto"> ' . _('Pièce') . ' : ' . $wPJ->input();
     $ret .= HtmlInput::hidden('e_pj_suggest', $default_pj);
     $ret .= '</tr>';
     $ret .= '</td>';
     $ret .= '<tr>';
     $ret .= '<td colspan="2" style="width:auto">';
     $ret .= _('Libellé');
     $wDescription = new IText('desc');
     $wDescription->readonly = $p_readonly;
     $wDescription->size = "50";
     $wDescription->value = isset($desc) ? $desc : '';
     $ret .= $wDescription->input();
     $ret .= '</td>';
     $ret .= '</tr>';
     $ret .= '</table>';
     $nb_row = isset($nb_item) ? $nb_item : $this->nb;
     $ret .= HtmlInput::hidden('nb_item', $nb_row);
     $ret .= dossier::hidden();
     $ret .= dossier::hidden();
     $ret .= HtmlInput::hidden('jrn_type', $this->get_type());
     $info = HtmlInput::infobulle(0);
     $info_poste = HtmlInput::infobulle(9);
     if ($g_user->check_action(FICADD) == 1) {
         $ret .= $f_add_button->input();
     }
     $ret .= '<table id="quick_item" style="position:float;width:100%">';
     $ret .= '<tr>' . '<th style="text-align:left">Quickcode' . $info . '</th>' . '<th style="text-align:left">' . _('Poste') . $info_poste . '</th>' . '<th style="text-align:left">' . _('Libellé') . '</th>' . '<th style="text-align:left">' . _('Montant') . '</th>' . '<th style="text-align:left">' . _('Débit') . '</th>' . '</tr>';
     for ($i = 0; $i < $nb_row; $i++) {
         // Quick Code
         $quick_code = new ICard('qc_' . $i);
         $quick_code->set_dblclick("fill_ipopcard(this);");
         $quick_code->set_attribute('ipopup', 'ipopcard');
         // name of the field to update with the name of the card
         $quick_code->set_attribute('label', "ld" . $i);
         // name of the field to update with the name of the card
         $quick_code->set_attribute('typecard', 'filter');
         // Add the callback function to filter the card on the jrn
         $quick_code->set_callback('filter_card');
         $quick_code->set_function('fill_data');
         $quick_code->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
         $quick_code->value = isset(${'qc_' . $i}) ? ${'qc_' . $i} : "";
         $quick_code->readonly = $p_readonly;
         $label = '';
         if ($quick_code->value != '') {
             $Fiche = new Fiche($this->db);
             $Fiche->get_by_qcode($quick_code->value);
             $label = $Fiche->strAttribut(ATTR_DEF_NAME);
         }
         // Account
         $poste = new IPoste();
         $poste->name = 'poste' . $i;
         $poste->set_attribute('jrn', $this->id);
         $poste->set_attribute('ipopup', 'ipop_account');
         $poste->set_attribute('label', 'ld' . $i);
         $poste->set_attribute('account', 'poste' . $i);
         $poste->set_attribute('dossier', Dossier::id());
         $poste->value = isset(${'poste' . $i}) ? ${"poste" . $i} : '';
         $poste->dbl_click_history();
         $poste->readonly = $p_readonly;
         if ($poste->value != '') {
             $Poste = new Acc_Account($this->db);
             $Poste->set_parameter('value', $poste->value);
             $label = $Poste->get_lib();
         }
         // Description of the line
         $line_desc = new IText();
         $line_desc->name = 'ld' . $i;
         $line_desc->size = 30;
         $line_desc->value = isset(${"ld" . $i}) ? ${"ld" . $i} : $label;
         // Amount
         $amount = new INum();
         $amount->size = 10;
         $amount->name = 'amount' . $i;
         $amount->value = isset(${'amount' . $i}) ? ${"amount" . $i} : '';
         $amount->readonly = $p_readonly;
         $amount->javascript = ' onChange="format_number(this);checkTotalDirect()"';
         // D/C
         $deb = new ICheckBox();
         $deb->name = 'ck' . $i;
         $deb->selected = isset(${'ck' . $i}) ? true : false;
         $deb->readonly = $p_readonly;
         $deb->javascript = ' onChange="checkTotalDirect()"';
         $ret .= '<tr>';
         $ret .= '<td>' . $quick_code->input() . $quick_code->search() . '</td>';
         $ret .= '<td>' . $poste->input() . '<script> document.getElementById(\'poste' . $i . '\').onblur=function(){ if (trim(this.value) !=\'\') {document.getElementById(\'qc_' . $i . '\').value="";}}</script>' . '</td>';
         $ret .= '<td>' . $line_desc->input() . '</td>';
         $ret .= '<td>' . $amount->input() . '</td>';
         $ret .= '<td>' . $deb->input() . '</td>';
         $ret .= '</tr>';
         // If readonly == 1 then show CA
     }
     $ret .= '</table>';
     if (isset($this->with_concerned) && $this->with_concerned == true) {
         $oRapt = new Acc_Reconciliation($this->db);
         $w = $oRapt->widget();
         $w->name = 'jrn_concerned';
         $w->value = isset($jrn_concerned) ? $jrn_concerned : "";
         $ret .= "R&eacute;conciliation/rapprochements : " . $w->input();
     }
     $ret .= create_script("\$('" . $wDate->id . "').focus()");
     return $ret;
 }
예제 #5
0
if ($pcmn_val != "-1") {
    // not set
}
$action = 'new';
$val = new IText('p_valu');
$parent = new IText('p_parentu');
$lib = new IText('p_libu');
$lib->css_size = "100%";
$type = new ISelect('p_typeu');
$type->value = Acc_Account::$type;
if ($pcmn_val != "") {
    $action = 'update';
    /*
     * Not empty, show the default value
     */
    $account = new Acc_Account($cn);
    $account->set_parameter('value', $pcmn_val);
    $account->load();
    $val->value = $account->get_parameter('value');
    $parent->value = $account->get_parameter('parent');
    $lib->value = $account->get_parameter('libelle');
    $type->selected = $account->get_parameter('type');
}
require 'template/pcmn_update.php';
$response = ob_get_clean();
$html = escape_xml($response);
if (headers_sent()) {
    echo $response;
    echo $html;
} else {
    header('Content-type: text/xml; charset=UTF-8');
예제 #6
0
 function display($p_array)
 {
     global $g_parameter, $g_user;
     require_once NOALYSS_INCLUDE . '/class_acc_ledger.php';
     $legder = new Acc_Ledger($this->db, $this->jrn_def_id);
     $legder->nb = $legder->get_min_row();
     if ($p_array != null) {
         extract($p_array);
     }
     $add_js = "";
     $ret = "";
     if ($g_user->check_action(FICADD) == 1) {
         /* Add button */
         $f_add_button = new IButton('add_card');
         $f_add_button->label = _('Créer une nouvelle fiche');
         $f_add_button->set_attribute('ipopup', 'ipop_newcard');
         $f_add_button->set_attribute('jrn', $legder->id);
         $f_add_button->javascript = " this.jrn=\$('p_jrn').value;select_card_type(this);";
         $f_add_button->input();
     }
     $nb_row = isset($nb_item) ? $nb_item : $legder->nb;
     $ret .= HtmlInput::hidden('nb_item', $nb_row);
     $ret .= HtmlInput::hidden('p_jrn', $this->jrn_def_id);
     $ret .= dossier::hidden();
     $ret .= dossier::hidden();
     $ret .= HtmlInput::hidden('jrn_type', $legder->get_type());
     $info = HtmlInput::infobulle(0);
     $info_poste = HtmlInput::infobulle(9);
     if ($g_user->check_action(FICADD) == 1) {
         $ret .= $f_add_button->input();
     }
     $ret .= '<table id="quick_item" style="width:100%">';
     $ret .= '<tr>' . '<th style="text-align:left">Quickcode' . $info . '</th>' . '<th style="text-align:left">' . _('Poste') . $info_poste . '</th>' . '<th style="text-align:left">' . _('Libellé') . '</th>' . '<th style="text-align:left">' . _('Montant') . '</th>' . '<th style="text-align:left">' . _('Débit') . '</th>' . '</tr>';
     for ($i = 0; $i < $nb_row; $i++) {
         // Quick Code
         $quick_code = new ICard('qc_' . $i);
         $quick_code->set_dblclick("fill_ipopcard(this);");
         $quick_code->set_attribute('ipopup', 'ipopcard');
         // name of the field to update with the name of the card
         $quick_code->set_attribute('label', "ld" . $i);
         $quick_code->set_attribute('jrn', $legder->id);
         // name of the field to update with the name of the card
         $quick_code->set_attribute('typecard', 'filter');
         // Add the callback function to filter the card on the jrn
         $quick_code->set_callback('filter_card');
         $quick_code->set_function('fill_data');
         $quick_code->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
         $quick_code->jrn = $legder->id;
         $quick_code->value = isset(${'qc_' . $i}) ? ${'qc_' . $i} : "";
         $label = '';
         if ($quick_code->value != '') {
             $Fiche = new Fiche($legder->db);
             $Fiche->get_by_qcode($quick_code->value);
             $label = $Fiche->strAttribut(ATTR_DEF_NAME);
         }
         // Account
         $poste = new IPoste();
         $poste->name = 'poste' . $i;
         $poste->set_attribute('jrn', $legder->id);
         $poste->set_attribute('ipopup', 'ipop_account');
         $poste->set_attribute('label', 'ld' . $i);
         $poste->set_attribute('account', 'poste' . $i);
         $poste->set_attribute('dossier', Dossier::id());
         $poste->value = isset(${'poste' . $i}) ? ${"poste" . $i} : '';
         $poste->dbl_click_history();
         if ($poste->value != '') {
             $Poste = new Acc_Account($legder->db);
             $Poste->set_parameter('value', $poste->value);
             $label = $Poste->get_lib();
         }
         // Description of the line
         $line_desc = new IText();
         $line_desc->name = 'ld' . $i;
         $line_desc->size = 30;
         $line_desc->value = isset(${"ld" . $i}) ? ${"ld" . $i} : $label;
         // Amount
         $amount = new INum();
         $amount->size = 10;
         $amount->name = 'amount' . $i;
         $amount->value = isset(${'amount' . $i}) ? ${"amount" . $i} : '';
         $amount->javascript = ' onChange="format_number(this);checkTotalDirect()"';
         // D/C
         $deb = new ICheckBox();
         $deb->name = 'ck' . $i;
         $deb->selected = isset(${'ck' . $i}) ? true : false;
         $deb->javascript = ' onChange="checkTotalDirect()"';
         $ret .= '<tr>';
         $ret .= '<td>' . $quick_code->input() . $quick_code->search() . '</td>';
         $ret .= '<td>' . $poste->input() . '<script> document.getElementById(\'poste' . $i . '\').onblur=function(){ if (trim(this.value) !=\'\') {document.getElementById(\'qc_' . $i . '\').value="";}}</script>' . '</td>';
         $ret .= '<td>' . $line_desc->input() . '</td>';
         $ret .= '<td>' . $amount->input() . '</td>';
         $ret .= '<td>' . $deb->input() . '</td>';
         $ret .= '</tr>';
         // If readonly == 1 then show CA
     }
     $ret .= '</table>';
     return $ret;
 }