/* set the width of the col */
    /* add hidden variables pa[] to hold the value of pa_id */
    $str_anc .= '<tr><th>Code</th><th>Montant</th><th colspan="' . $x . '">' . _('Compt. Analytique') . Anc_Plan::hidden($a_anc) . '</th></tr>';
}
echo '</tr>';
for ($e = 0; $e < count($obj->det->array); $e++) {
    $row = '';
    $q = $obj->det->array[$e];
    $fiche = new Fiche($cn, $q['qp_fiche']);
    $qcode = $fiche->strAttribut(ATTR_DEF_QUICKCODE);
    $view_card_detail = HtmlInput::card_detail($qcode, "", ' class="line" ');
    $row = td($view_card_detail);
    $sym_tva = '';
    if ($owner->MY_TVA_USE == 'Y' && $q['qp_vat_code'] != '') {
        /* retrieve TVA symbol */
        $tva = new Acc_Tva($cn, $q['qp_vat_code']);
        $tva->load();
        $sym_tva = h($tva->get_parameter('label'));
    }
    if ($owner->MY_UPDLAB == 'Y') {
        $l_lib = $q['j_text'] == '' ? $fiche->strAttribut(ATTR_DEF_NAME) : $q['j_text'];
        $hidden = HtmlInput::hidden("j_id[]", $q['j_id']);
        $input = new IText("e_march" . $q['j_id'] . "_label", $l_lib);
        $input->css_size = "100%";
    } else {
        $input = new ISpan("e_march" . $q['j_id'] . "_label");
        $hidden = HtmlInput::hidden("j_id[]", $q['j_id']);
        $input->value = $fiche->strAttribut(ATTR_DEF_NAME);
    }
    $row .= td($input->input() . $hidden);
    $row .= td($sym_tva, 'style="text-align:center"');
Beispiel #2
0
 static function test_me()
 {
     $cn = new Database(dossier::id());
     $a = new Acc_Tva($cn);
     echo $a->get_info();
     $a->set_parameter("id", 1);
     $a->load();
     $a->set_parameter("id", 0);
     $a->set_parameter("rate", "0.2222");
     $a->set_parameter("label", "test");
     $a->save();
     $a->load();
     print_r($a);
     $a->set_parameter("comment", "un cht'it test");
     $a->save();
     $a->load();
     print_r($a);
     $a->delete();
 }
Beispiel #3
0
 function Replace($p_tag, $p_array)
 {
     global $g_parameter;
     $p_tag = strtoupper($p_tag);
     $p_tag = str_replace('=', '', $p_tag);
     $r = "Tag inconnu";
     switch ($p_tag) {
         case 'DATE':
             $r = isset($p_array['ag_timestamp']) ? $p_array['ag_timestamp'] : $p_array['e_date'];
             break;
         case 'DATE_CALC':
             $r = ' Date inconnue ';
             // Date are in $p_array['ag_date']
             // or $p_array['e_date']
             if (isset($p_array['ag_timestamp'])) {
                 $date = format_date($p_array['ag_timestamp'], 'DD.MM.YYYY', 'YYYY-MM-DD');
                 $r = $date;
             }
             if (isset($p_array['e_date'])) {
                 $date = format_date($p_array['e_date'], 'DD.MM.YYYY', 'YYYY-MM-DD');
                 $r = $date;
             }
             break;
             //
             //  the company priv
         //
         //  the company priv
         case 'MY_NAME':
             $r = $g_parameter->MY_NAME;
             break;
         case 'MY_CP':
             $r = $g_parameter->MY_CP;
             break;
         case 'MY_COMMUNE':
             $r = $g_parameter->MY_COMMUNE;
             break;
         case 'MY_TVA':
             $r = $g_parameter->MY_TVA;
             break;
         case 'MY_STREET':
             $r = $g_parameter->MY_STREET;
             break;
         case 'MY_NUMBER':
             $r = $g_parameter->MY_NUMBER;
             break;
         case 'MY_TEL':
             $r = $g_parameter->MY_TEL;
             break;
         case 'MY_FAX':
             $r = $g_parameter->MY_FAX;
             break;
         case 'MY_PAYS':
             $r = $g_parameter->MY_PAYS;
             break;
             // customer
             /*\note The CUST_* are retrieved thx the $p_array['tiers']
              * which contains the quick_code
              */
         // customer
         /*\note The CUST_* are retrieved thx the $p_array['tiers']
          * which contains the quick_code
          */
         case 'SOLDE':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $tiers->get_by_qcode($qcode, false);
             $p = $tiers->strAttribut(ATTR_DEF_ACCOUNT);
             $poste = new Acc_Account_Ledger($this->db, $p);
             $r = $poste->get_solde(' true');
             break;
         case 'CUST_NAME':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_NAME);
             break;
         case 'CUST_ADDR_1':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_ADRESS);
             break;
         case 'CUST_CP':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_CP);
             break;
         case 'CUST_CITY':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_CITY);
             break;
         case 'CUST_CO':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_PAYS);
             break;
             // Marchandise in $p_array['e_march*']
             // \see user_form_achat.php or user_form_ven.php
         // Marchandise in $p_array['e_march*']
         // \see user_form_achat.php or user_form_ven.php
         case 'CUST_VAT':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_NUMTVA);
             break;
         case 'CUST_NUM':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
             break;
         case 'CUST_BANQUE_NO':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_BQ_NO);
             break;
         case 'CUST_BANQUE_NAME':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_BQ_NAME);
             break;
             /* -------------------------------------------------------------------------------- */
             /* BENEFIT (fee notes */
         /* -------------------------------------------------------------------------------- */
         /* BENEFIT (fee notes */
         case 'BENEF_NAME':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : '';
             if ($qcode == '') {
                 $r = '';
                 break;
             }
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_NAME);
             break;
         case 'BENEF_ADDR_1':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : '';
             if ($qcode == '') {
                 $r = '';
                 break;
             }
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_ADRESS);
             break;
         case 'BENEF_CP':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : '';
             if ($qcode == '') {
                 $r = '';
                 break;
             }
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_CP);
             break;
         case 'BENEF_CITY':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : '';
             if ($qcode == '') {
                 $r = '';
                 break;
             }
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_CITY);
             break;
         case 'BENEF_CO':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : '';
             if ($qcode == '') {
                 $r = '';
                 break;
             }
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_PAYS);
             break;
             // Marchandise in $p_array['e_march*']
             // \see user_form_achat.php or user_form_ven.php
         // Marchandise in $p_array['e_march*']
         // \see user_form_achat.php or user_form_ven.php
         case 'BENEF_VAT':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : '';
             if ($qcode == '') {
                 $r = '';
                 break;
             }
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_NUMTVA);
             break;
         case 'BENEF_NUM':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : '';
             if ($qcode == '') {
                 $r = '';
                 break;
             }
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
             break;
         case 'BENEF_BANQUE_NO':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : '';
             if ($qcode == '') {
                 $r = '';
                 break;
             }
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_BQ_NO);
             break;
         case 'BENEF_BANQUE_NAME':
             $tiers = new Fiche($this->db);
             $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : '';
             if ($qcode == '') {
                 $r = '';
                 break;
             }
             $tiers->get_by_qcode($qcode, false);
             $r = $tiers->strAttribut(ATTR_DEF_BQ_NAME);
             break;
             // Marchandise in $p_array['e_march*']
             // \see user_form_achat.php or user_form_ven.php
         // Marchandise in $p_array['e_march*']
         // \see user_form_achat.php or user_form_ven.php
         case 'NUMBER':
             $r = $this->d_number;
             break;
         case 'USER':
             return $_SESSION['use_name'] . ', ' . $_SESSION['use_first_name'];
             break;
         case 'REFERENCE':
             $act = new Follow_Up($this->db);
             $act->ag_id = $this->ag_id;
             $act->get();
             $r = $act->ag_ref;
             break;
             /*
              *  - [VEN_ART_NAME]
              *  - [VEN_ART_PRICE]
              *  - [VEN_ART_QUANT]
              *  - [VEN_ART_TVA_CODE]
              *  - [VEN_ART_STOCK_CODE]
              *  - [VEN_HTVA]
              *  - [VEN_TVAC]
              *  - [VEN_TVA]
              *  - [TOTAL_VEN_HTVA]
              *  - [DATE_LIMIT]
              */
         /*
          *  - [VEN_ART_NAME]
          *  - [VEN_ART_PRICE]
          *  - [VEN_ART_QUANT]
          *  - [VEN_ART_TVA_CODE]
          *  - [VEN_ART_STOCK_CODE]
          *  - [VEN_HTVA]
          *  - [VEN_TVAC]
          *  - [VEN_TVA]
          *  - [TOTAL_VEN_HTVA]
          *  - [DATE_LIMIT]
          */
         case 'DATE_LIMIT_CALC':
             extract($p_array);
             $id = 'e_ech';
             if (!isset(${$id})) {
                 return "";
             }
             $r = format_date(${$id}, 'DD.MM.YYYY', 'YYYY-MM-DD');
             break;
         case 'DATE_LIMIT':
             extract($p_array);
             $id = 'e_ech';
             if (!isset(${$id})) {
                 return "";
             }
             $r = ${$id};
             break;
         case 'MARCH_NEXT':
             $this->counter++;
             $r = '';
             break;
         case 'VEN_ART_NAME':
             extract($p_array);
             $id = 'e_march' . $this->counter;
             // check if the march exists
             if (!isset(${$id})) {
                 return "";
             }
             // check that something is sold
             if (${'e_march' . $this->counter . '_price'} != 0 && ${'e_quant' . $this->counter} != 0) {
                 $f = new Fiche($this->db);
                 $f->get_by_qcode(${$id}, false);
                 $r = $f->strAttribut(ATTR_DEF_NAME);
             } else {
                 $r = "";
             }
             break;
         case 'VEN_ART_LABEL':
             extract($p_array);
             $id = 'e_march' . $this->counter . "_label";
             // check if the march exists
             if (!isset(${$id}) || isset(${$id}) && strlen(trim(${$id})) == 0) {
                 $id = 'e_march' . $this->counter;
                 // check if the march exists
                 if (!isset(${$id})) {
                     $r = "";
                 } else {
                     // check that something is sold
                     if (${'e_march' . $this->counter . '_price'} != 0 && ${'e_quant' . $this->counter} != 0) {
                         $f = new Fiche($this->db);
                         $f->get_by_qcode(${$id}, false);
                         $r = $f->strAttribut(ATTR_DEF_NAME);
                     } else {
                         $r = "";
                     }
                 }
             } else {
                 $r = ${'e_march' . $this->counter . '_label'};
             }
             break;
         case 'VEN_ART_STOCK_CODE':
             extract($p_array);
             $id = 'e_march' . $this->counter;
             // check if the march exists
             if (!isset(${$id})) {
                 $r = "";
             } else {
                 // check that something is sold
                 if (${'e_march' . $this->counter . '_price'} != 0 && ${'e_quant' . $this->counter} != 0) {
                     $f = new Fiche($this->db);
                     $f->get_by_qcode(${$id}, false);
                     $r = $f->strAttribut(ATTR_DEF_STOCK);
                     $r = $r == NOTFOUND ? '' : $r;
                 }
             }
             break;
         case 'VEN_ART_PRICE':
             extract($p_array);
             $id = 'e_march' . $this->counter . '_price';
             if (!isset(${$id})) {
                 return "";
             }
             if (${$id} == 0) {
                 return "";
             }
             $r = ${$id};
             break;
         case 'TVA_RATE':
         case 'VEN_ART_TVA_RATE':
             extract($p_array);
             $id = 'e_march' . $this->counter . '_tva_id';
             if (!isset(${$id})) {
                 return "";
             }
             if (${$id} == -1 || ${$id} == '') {
                 return "";
             }
             $march_id = 'e_march' . $this->counter . '_price';
             if (!isset(${$march_id})) {
                 return '';
             }
             $tva = new Acc_Tva($this->db);
             $tva->set_parameter("id", ${$id});
             if ($tva->load() == -1) {
                 return '';
             }
             return $tva->get_parameter("rate");
             break;
         case 'TVA_CODE':
         case 'VEN_ART_TVA_CODE':
             extract($p_array);
             $id = 'e_march' . $this->counter . '_tva_id';
             if (!isset(${$id})) {
                 return "";
             }
             if (${$id} == -1) {
                 return "";
             }
             $qt = 'e_quant' . $this->counter;
             $price = 'e_march' . $this->counter . '_price';
             if (${$price} == 0 || ${$qt} == 0 || strlen(trim($price)) == 0 || strlen(trim($qt)) == 0) {
                 return "";
             }
             $r = ${$id};
             break;
         case 'TVA_LABEL':
             extract($p_array);
             $id = 'e_march' . $this->counter . '_tva_id';
             if (!isset(${$id})) {
                 return "";
             }
             $march_id = 'e_march' . $this->counter . '_price';
             if (!isset(${$march_id})) {
                 return '';
             }
             if (${$march_id} == 0) {
                 return '';
             }
             $tva = new Acc_Tva($this->db, ${$id});
             if ($tva->load() == -1) {
                 return "";
             }
             $r = $tva->get_parameter('label');
             break;
             /* total VAT for one sold */
         /* total VAT for one sold */
         case 'TVA_AMOUNT':
         case 'VEN_TVA':
             extract($p_array);
             $qt = 'e_quant' . $this->counter;
             $price = 'e_march' . $this->counter . '_price';
             $tva = 'e_march' . $this->counter . '_tva_id';
             /* if we do not use vat this var. is not set */
             if (!isset(${$tva})) {
                 return '';
             }
             if (!isset(${'e_march' . $this->counter})) {
                 return "";
             }
             // check that something is sold
             if (${$price} == 0 || ${$qt} == 0 || strlen(trim($price)) == 0 || strlen(trim($qt)) == 0) {
                 return "";
             }
             $r = ${'e_march' . $this->counter . '_tva_amount'};
             break;
             /* TVA automatically computed */
         /* TVA automatically computed */
         case 'VEN_ART_TVA':
             extract($p_array);
             $qt = 'e_quant' . $this->counter;
             $price = 'e_march' . $this->counter . '_price';
             $tva = 'e_march' . $this->counter . '_tva_id';
             if (!isset(${'e_march' . $this->counter})) {
                 return "";
             }
             // check that something is sold
             if (${$price} == 0 || ${$qt} == 0 || strlen(trim($price)) == 0 || strlen(trim($qt)) == 0) {
                 return "";
             }
             $oTva = new Acc_Tva($this->db, ${$tva});
             if ($oTva->load() == -1) {
                 return "";
             }
             $r = round(${$price}, 2) * $oTva->get_parameter('rate');
             $r = round($r, 2);
             break;
         case 'VEN_ART_TVAC':
             extract($p_array);
             $qt = 'e_quant' . $this->counter;
             $price = 'e_march' . $this->counter . '_price';
             $tva = 'e_march' . $this->counter . '_tva_id';
             if (!isset(${'e_march' . $this->counter})) {
                 return "";
             }
             // check that something is sold
             if (${$price} == 0 || ${$qt} == 0 || strlen(trim($price)) == 0 || strlen(trim($qt)) == 0) {
                 return "";
             }
             if (!isset(${$tva})) {
                 return '';
             }
             $tva = new Acc_Tva($this->db, ${$tva});
             if ($tva->load() == -1) {
                 $r = round(${$price}, 2);
             } else {
                 $r = round(${$price} * $tva->get_parameter('rate') + ${$price}, 2);
             }
             break;
         case 'VEN_ART_QUANT':
             extract($p_array);
             $id = 'e_quant' . $this->counter;
             if (!isset(${$id})) {
                 return "";
             }
             // check that something is sold
             if (${'e_march' . $this->counter . '_price'} == 0 || ${'e_quant' . $this->counter} == 0 || strlen(trim(${'e_march' . $this->counter . '_price'})) == 0 || strlen(trim(${'e_quant' . $this->counter})) == 0) {
                 return "";
             }
             $r = ${$id};
             break;
         case 'VEN_HTVA':
             extract($p_array);
             $id = 'e_march' . $this->counter . '_price';
             $quant = 'e_quant' . $this->counter;
             if (!isset(${$id})) {
                 return "";
             }
             // check that something is sold
             if (${'e_march' . $this->counter . '_price'} == 0 || ${'e_quant' . $this->counter} == 0 || strlen(trim(${'e_march' . $this->counter . '_price'})) == 0 || strlen(trim(${'e_quant' . $this->counter})) == 0) {
                 return "";
             }
             bcscale(4);
             $r = bcmul(${$id}, ${$quant});
             $r = round($r, 2);
             break;
         case 'VEN_TVAC':
             extract($p_array);
             $id = 'e_march' . $this->counter . '_tva_amount';
             $price = 'e_march' . $this->counter . '_price';
             $quant = 'e_quant' . $this->counter;
             if (!isset(${'e_march' . $this->counter . '_price'}) || !isset(${'e_quant' . $this->counter})) {
                 return "";
             }
             // check that something is sold
             if (${'e_march' . $this->counter . '_price'} == 0 || ${'e_quant' . $this->counter} == 0) {
                 return "";
             }
             bcscale(4);
             // if TVA not exist
             if (!isset(${$id})) {
                 $r = bcmul(${$price}, ${$quant});
             } else {
                 $r = bcmul(${$price}, ${$quant});
                 $r = bcadd($r, ${$id});
             }
             $r = round($r, 2);
             return $r;
             break;
         case 'TOTAL_VEN_HTVA':
             extract($p_array);
             bcscale(4);
             $sum = 0.0;
             for ($i = 0; $i < $nb_item; $i++) {
                 $sell = 'e_march' . $i . '_price';
                 $qt = 'e_quant' . $i;
                 if (!isset(${$sell})) {
                     break;
                 }
                 if (strlen(trim(${$sell})) == 0 || strlen(trim(${$qt})) == 0 || ${$qt} == 0 || ${$sell} == 0) {
                     continue;
                 }
                 $tmp1 = bcmul(${$sell}, ${$qt});
                 $sum = bcadd($sum, $tmp1);
             }
             $r = round($sum, 2);
             break;
         case 'TOTAL_VEN_TVAC':
             extract($p_array);
             $sum = 0.0;
             bcscale(4);
             for ($i = 0; $i < $nb_item; $i++) {
                 $tva = 'e_march' . $i . '_tva_amount';
                 $tva_amount = 0;
                 /* if we do not use vat this var. is not set */
                 if (isset(${$tva})) {
                     $tva_amount = ${$tva};
                 }
                 $sell = ${'e_march' . $i . '_price'};
                 $qt = ${'e_quant' . $i};
                 $tot = bcmul($sell, $qt);
                 $tot = bcadd($tot, $tva_amount);
                 $sum = bcadd($sum, $tot);
             }
             $r = round($sum, 2);
             break;
         case 'TOTAL_TVA':
             extract($p_array);
             $sum = 0.0;
             for ($i = 0; $i < $nb_item; $i++) {
                 $tva = 'e_march' . $i . '_tva_amount';
                 if (!isset(${$tva})) {
                     $tva_amount = 0.0;
                 } else {
                     $tva_amount = ${$tva};
                 }
                 $sum += $tva_amount;
                 $sum = round($sum, 2);
             }
             $r = $sum;
             break;
         case 'BON_COMMANDE':
             if (isset($p_array['bon_comm'])) {
                 return $p_array['bon_comm'];
             } else {
                 return "";
             }
             break;
         case 'PJ':
             if (isset($p_array['e_pj'])) {
                 return $p_array['e_pj'];
             } else {
                 return "";
             }
         case 'OTHER_INFO':
             if (isset($p_array['other_info'])) {
                 return $p_array['other_info'];
             } else {
                 return "";
             }
             break;
         case 'COMMENT':
             if (isset($p_array['e_comm'])) {
                 return $p_array['e_comm'];
             }
             break;
         case 'ACOMPTE':
             if (isset($p_array['acompte'])) {
                 return $p_array['acompte'];
             }
             return "0";
             break;
         case 'STOCK_NAME':
             if (!isset($p_array['repo'])) {
                 return "";
             }
             $ret = $this->db->get_value('select r_name from public.stock_repository where r_id=$1', array($p_array['repo']));
             return $ret;
         case 'STOCK_ADRESS':
             if (!isset($p_array['repo'])) {
                 return "";
             }
             $ret = $this->db->get_value('select r_adress from public.stock_repository where r_id=$1', array($p_array['repo']));
             return $ret;
         case 'STOCK_COUNTRY':
             if (!isset($p_array['repo'])) {
                 return "";
             }
             $ret = $this->db->get_value('select r_country from public.stock_repository where r_id=$1', array($p_array['repo']));
             return $ret;
         case 'STOCK_CITY':
             if (!isset($p_array['repo'])) {
                 return "";
             }
             $ret = $this->db->get_value('select r_city from public.stock_repository where r_id=$1', array($p_array['repo']));
             return $ret;
         case 'STOCK_PHONE':
             if (!isset($p_array['repo'])) {
                 return "";
             }
             $ret = $this->db->get_value('select r_phone from public.stock_repository where r_id=$1', array($p_array['repo']));
             return $ret;
         case 'TITLE':
             $title = HtmlInput::default_value_request("ag_title", "");
             return $title;
     }
     /*
      * retrieve the value of ATTR for e_march
      */
     if (preg_match('/^ATTR/', $p_tag) == 1) {
         // Retrieve f_id
         if (isset($p_array['e_march' . $this->counter])) {
             $id = $p_array['e_march' . $this->counter];
             $r = $this->replace_special_tag($id, $p_tag);
         }
     }
     /*
      * retrieve the value of ATTR for e_march
      */
     if (preg_match('/^BENEFATTR/', $p_tag) == 1) {
         $qcode = isset($p_array['qcode_benef']) ? $p_array['qcode_benef'] : '';
         // Retrieve f_id
         $r = $this->replace_special_tag($qcode, $p_tag);
     }
     if (preg_match('/^CUSTATTR/', $p_tag) == 1) {
         if (isset($p_array['qcode_dest']) || isset($p_array['e_client'])) {
             $qcode = isset($p_array['qcode_dest']) ? $p_array['qcode_dest'] : $p_array['e_client'];
             $r = $this->replace_special_tag($qcode, $p_tag);
         }
     }
     return $r;
 }
 public function display()
 {
     $cn = new Database(Dossier::id());
     $tva = new Acc_Tva($cn, $this->value);
     $comment = $tva->load() != "-1" ? $tva->tva_label : "";
     $res = sprintf('<input type="text" name="%s" size="6" class="input_text_ro" value="%s" id="%s" readonly="">%s', $this->name, $this->value, $this->name, $comment);
     return $res;
 }
Beispiel #5
0
require_once NOALYSS_INCLUDE . '/class_acc_tva.php';
require_once NOALYSS_INCLUDE . '/class_user.php';
// Check if the needed field does exist
extract($_GET);
foreach (array('t', 'c', 'p', 'q', 'n', 'gDossier') as $a) {
    if (!isset(${$a})) {
        echo "error {$a} is not set ";
        exit;
    }
}
$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();
    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;
    }