/**
  * @covers Acc_Compute::test_me
  * @todo   Implement testTest_me().
  */
 public function testTest_me()
 {
     $this->object->test_me();
     $this->assertTrue(true, true);
 }
Exemple #2
0
}
$cn = new Database(dossier::id());
$User = new User($cn);
$User->Check();
// Retrieve the rate of vat, it $t == -1 it means no VAT
if ($t != -1 && isNumber($t) == 1) {
    $tva_rate = new Acc_Tva($cn);
    $tva_rate->set_parameter('id', $t);
    /**
     *if the tva_rate->load failed we don't compute tva
     */
    if ($tva_rate->load() != 0) {
        $tva_rate->set_parameter('rate', 0);
    }
}
$total = new Acc_Compute();
bcscale(4);
$amount = round(bcmul($p, $q), 2);
$total->set_parameter('amount', $amount);
if ($t != -1 && isNumber($t) == 1) {
    $total->set_parameter('amount_vat_rate', $tva_rate->get_parameter('rate'));
    $total->compute_vat();
    if ($tva_rate->get_parameter('both_side') == 1) {
        $total->set_parameter('amount_vat', 0);
    }
    $tvac = $tva_rate->get_parameter('rate') == 0 || $tva_rate->get_parameter('both_side') == 1 ? $amount : bcadd($total->get_parameter('amount_vat'), $amount);
    header("Content-type: text/html; charset: utf8", true);
    echo '{"ctl":"' . $n . '","htva":"' . $amount . '","tva":"' . $total->get_parameter('amount_vat') . '","tvac":"' . $tvac . '"}';
} else {
    /* there is no vat to compute */
    header("Content-type: text/html; charset: utf8", true);
 public static function test_me()
 {
     $a = new Acc_Compute();
     echo $a->get_info();
     echo '<hr>';
     // Compute some operation to see if the computed amount are
     // correct
     //Test VAT
     $a->set_parameter('amount', 1.23);
     $a->set_parameter('amount_vat_rate', 0.21);
     echo '<h1> Test VAT </h1>';
     echo '<h2> Data </h2>';
     $a->display();
     echo '<h2> Result </h2>';
     $a->compute_vat();
     $a->display();
     $a->verify();
     // Test VAT + perso
     $a = new Acc_Compute();
     $a->set_parameter('amount', 1.23);
     $a->set_parameter('amount_vat_rate', 0.21);
     $a->set_parameter('amount_perso_rate', 0.5);
     echo '<h1> Test VAT + Perso</h1>';
     echo '<h2> Data </h2>';
     $a->display();
     $b = clone $a;
     $a->compute_vat();
     $a->compute_perso();
     $a->correct();
     echo '<h2> Result </h2>';
     $a->display();
     $a->verify($b);
     // TEST VAT + ND
     // Test VAT + perso
     $a = new Acc_Compute();
     $a->set_parameter('amount', 1.23);
     $a->set_parameter('amount_vat_rate', 0.21);
     $a->set_parameter('nd_vat_rate', 0.5);
     $b = clone $a;
     echo '<h1> Test VAT + ND VAT</h1>';
     echo '<h2> Data </h2>';
     $a->display();
     $a->compute_vat();
     $a->compute_nd_vat();
     $a->correct();
     echo '<h2> Result </h2>';
     $a->display();
     $a->verify($b);
     // TEST VAT + ND
     // Test VAT + perso
     $a = new Acc_Compute();
     $a->set_parameter('amount', 1.23);
     $a->set_parameter('amount_vat_rate', 0.21);
     $a->set_parameter('nd_vat_rate', 0.5);
     $a->set_parameter('amount_perso_rate', 0.5);
     $b = clone $a;
     echo '<h1> Test VAT + ND VAT + perso</h1>';
     echo '<h2> Data </h2>';
     $a->display();
     $a->compute_vat();
     $a->compute_perso();
     $a->compute_nd_vat();
     $a->correct();
     echo '<h2> Result </h2>';
     $a->display();
     $a->verify($b);
     // TEST VAT + ND
     $a = new Acc_Compute();
     $a->set_parameter('amount', 1.23);
     $a->set_parameter('amount_vat_rate', 0.21);
     $a->set_parameter('amount_nd_rate', 0.5);
     $b = clone $a;
     echo '<h1> Test VAT + ND </h1>';
     echo '<h2> Data </h2>';
     $a->display();
     $a->compute_vat();
     $a->compute_nd();
     $a->compute_perso();
     $a->compute_nd_vat();
     $a->correct();
     echo '<h2> Result </h2>';
     $a->display();
     $a->verify($b);
     // TEST VAT + ND
     // + Perso
     $a = new Acc_Compute();
     $a->set_parameter('amount', 1.23);
     $a->set_parameter('amount_vat_rate', 0.21);
     $a->set_parameter('amount_nd_rate', 0.5);
     $a->set_parameter('amount_perso_rate', 0.2857);
     $b = clone $a;
     echo '<h1> Test VAT + ND  + Perso</h1>';
     echo '<h2> Data </h2>';
     $a->display();
     $a->compute_vat();
     $a->compute_nd();
     $a->compute_perso();
     $a->compute_nd_vat();
     $a->correct();
     echo '<h2> Result </h2>';
     $a->display();
     $a->verify($b);
     // TEST VAT + ND
     // + Perso
     $a = new Acc_Compute();
     $a->set_parameter('amount', 1.23);
     $a->set_parameter('amount_vat_rate', 0.21);
     $a->set_parameter('nd_ded_vat_rate', 0.5);
     $b = clone $a;
     echo '<h1> Test VAT   +  TVA ND DED</h1>';
     echo '<h2> Data </h2>';
     $a->display();
     $a->compute_vat();
     $a->compute_nd();
     $a->compute_perso();
     $a->compute_nd_vat();
     $a->compute_ndded_vat();
     $a->correct();
     echo '<h2> Result </h2>';
     $a->display();
     $a->verify($b);
 }
    function confirm($p_array, $p_summary = false)
    {
        global $g_parameter;
        extract($p_array);
        // don't need to verify for a summary
        if (!$p_summary) {
            $this->verify($p_array);
        }
        $anc = null;
        // to show a select list for the analytic & VAT USE
        // 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 = $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 .= '<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 .= '<td> ' . _('Client') . '</td><td> ' . hb($e_client . ':' . $client_name) . '</td>';
        $r .= '</tr>';
        $r .= '</table>';
        $r .= '<h2>' . _('Détail articles vendus') . '</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 ($i = 0; $i < $nb_item; $i++) {
            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);
            }
            if ($g_parameter->MY_TVA_USE == 'Y') {
                $oTva = new Acc_Tva($this->db);
                $idx_tva = ${"e_march" . $i . "_tva_id"};
                $oTva->set_parameter('id', $idx_tva);
                $oTva->load();
            }
            $op = new Acc_Compute();
            $amount = bcmul(${"e_march" . $i . "_price"}, ${'e_quant' . $i});
            $op->set_parameter("amount", $amount);
            if ($g_parameter->MY_TVA_USE == 'Y') {
                $op->set_parameter('amount_vat_rate', $oTva->get_parameter('rate'));
                $op->compute_vat();
                $tva_computed = $op->get_parameter('amount_vat');
                $tva_item = ${"e_march" . $i . "_tva_amount"};
                if (isset($tva[$idx_tva])) {
                    $tva[$idx_tva] += $tva_item;
                } else {
                    $tva[$idx_tva] = $tva_item;
                }
                $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
            }
            $tot_amount = round(bcadd($tot_amount, $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');
                $r .= '</td>';
                $both_side = $oTva->get_parameter("both_side");
                /* warning if tva_computed and given are not the
                   same */
                if (bcsub($tva_item, $tva_computed) != 0 && !($tva_item == 0 && $both_side == 1)) {
                    $r .= '<td style="background-color:red" class="num">';
                    $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">';
                    $r .= nbm($tva_item);
                }
                $r .= '</td>';
                $r .= '<td class="num">';
                $r .= nbm($amount);
                $r .= '</td>';
                $tot_row = bcadd($tva_item, $amount);
                $r .= td(nbm($tot_row), 'class="num"');
            } else {
                $r .= '<td class="num">';
                $r .= nbm($amount);
                $r .= '</td>';
            }
            // encode the pa
            if ($g_parameter->MY_ANALYTIC != 'nu') {
                // use of AA
                // 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>';
        }
        // end loop item
        //
        // 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);
        $mt = microtime(true);
        $r .= HtmlInput::hidden('mt', $mt);
        if (isset($period)) {
            $r .= HtmlInput::hidden('period', $period);
        }
        /* \todo comment les types hidden gérent ils des contenus avec des quotes, double quote ou < > ??? */
        $r .= HtmlInput::hidden('e_comm', $e_comm);
        $r .= HtmlInput::hidden('e_date', $e_date);
        $r .= HtmlInput::hidden('e_ech', $e_ech);
        $r .= HtmlInput::hidden('e_pj', $e_pj);
        $r .= HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
        $e_mp = isset($e_mp) ? $e_mp : 0;
        $r .= HtmlInput::hidden('e_mp', $e_mp);
        if (isset($repo)) {
            // Show the available repository
            $r .= $this->select_depot($p_summary, $repo);
        }
        /* if the paymethod is not 0 and if a quick code is given */
        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 .= HtmlInput::hidden('jrn_type', $jrn_type);
        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});
        }
        return $r;
    }