public function verify($p_array)
 {
     global $g_parameter, $g_user;
     if (is_array($p_array) == false || empty($p_array)) {
         throw new Exception("Array empty");
     }
     extract($p_array);
     /*
      * Check needed value
      */
     check_parameter($p_array, 'p_jrn,e_date,e_client');
     /* check for a double reload */
     if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt)) != 0) {
         throw new Exception(_('Double Encodage'), 5);
     }
     /* check if we can write into this ledger */
     if ($g_user->check_jrn($p_jrn) != 'W') {
         throw new Exception(_('Accès interdit'), 20);
     }
     /* check if there is a customer */
     if (strlen(trim($e_client)) == 0) {
         throw new Exception(_('Vous n\'avez pas donné de client'), 11);
     }
     /*  check if the date is valid */
     if (isDate($e_date) == null) {
         throw new Exception(_('Date invalide'), 2);
     }
     $oPeriode = new Periode($this->db);
     if ($this->check_periode() == true) {
         $tperiode = $period;
         /* check that the datum is in the choosen periode */
         $oPeriode->p_id = $period;
         list($min, $max) = $oPeriode->get_date_limit();
         if (cmpDate($e_date, $min) < 0 || cmpDate($e_date, $max) > 0) {
             throw new Exception(_('Date et periode ne correspondent pas'), 6);
         }
     } else {
         $per = new Periode($this->db);
         $tperiode = $per->find_periode($e_date);
     }
     /* check if the periode is closed */
     if ($this->is_closed($tperiode) == 1) {
         throw new Exception(_('Periode fermee'), 6);
     }
     /* check if we are using the strict mode */
     if ($this->check_strict() == true) {
         /* if we use the strict mode, we get the date of the last
            operation */
         $last_date = $this->get_last_date();
         if ($last_date != null && cmpDate($e_date, $last_date) < 0) {
             throw new Exception(_('Vous utilisez le mode strict la dernière operation est date du ') . $last_date . _(' vous ne pouvez pas encoder à une date antérieure'), 13);
         }
     }
     $fiche = new Fiche($this->db);
     $fiche->get_by_qcode($e_client);
     if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true) {
         throw new Exception(_('La fiche ') . $e_client . _('n\'a pas de poste comptable'), 8);
     }
     /* get the account and explode if necessary */
     $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
     // if 2 accounts, take only the debit one for customer
     if (strpos($sposte, ',') != 0) {
         $array = explode(',', $sposte);
         $poste_val = $array[0];
     } else {
         $poste_val = $sposte;
     }
     /* The account exists */
     $poste = new Acc_Account_Ledger($this->db, $poste_val);
     if ($poste->load() == false) {
         throw new Exception(_('Pour la fiche ') . $e_client . _(' le poste comptable [') . $poste->id . _('] n\'existe pas'), 9);
     }
     /* Check if the card belong to the ledger */
     $fiche = new Fiche($this->db);
     $fiche->get_by_qcode($e_client, 'deb');
     if ($fiche->belong_ledger($p_jrn) != 1) {
         throw new Exception(_('La fiche ') . $e_client . _('n\'est pas accessible à ce journal'), 10);
     }
     $nb = 0;
     //----------------------------------------
     // foreach item
     //----------------------------------------
     for ($i = 0; $i < $nb_item; $i++) {
         if (strlen(trim(${'e_march' . $i})) == 0) {
             continue;
         }
         /* check if amount are numeric and */
         if (isNumber(${'e_march' . $i . '_price'}) == 0) {
             throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un montant invalide [') . ${'e_march' . $i} . ']', 6);
         }
         if (isNumber(${'e_quant' . $i}) == 0) {
             throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a une quantité invalide [') . ${'e_quant' . $i} . ']', 7);
         }
         /* check if all card has a ATTR_DEF_ACCOUNT */
         $fiche = new Fiche($this->db);
         $fiche->get_by_qcode(${'e_march' . $i});
         if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true) {
             throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'a pas de poste comptable'), 8);
         }
         // Check if the given tva id is valid
         if ($g_parameter->MY_TVA_USE == 'Y') {
             if (isNumber(${'e_march' . $i . '_tva_id'}) == 0) {
                 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
             }
             $tva_rate = new Acc_Tva($this->db);
             $tva_rate->set_parameter('id', ${'e_march' . $i . '_tva_id'});
             if ($tva_rate->load() != 0) {
                 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
             }
             /*
              * check if the accounting for VAT are valid
              */
             $a_poste = explode(',', $tva_rate->tva_poste);
             if ($this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1', array($a_poste[0])) == 0 || $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1', array($a_poste[1])) == 0) {
                 throw new Exception(_(" La TVA " . $tva_rate->tva_label . " utilise des postes comptables inexistants"));
             }
         }
         // if 2 accounts, take only the credit one
         /* The account exists */
         $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
         if (strpos($sposte, ',') != 0) {
             $array = explode(',', $sposte);
             $poste_val = $array[1];
         } else {
             $poste_val = $sposte;
         }
         $poste = new Acc_Account_Ledger($this->db, $poste_val);
         if ($poste->load() == false) {
             throw new Exception(_('Pour la fiche ') . ${'e_march' . $i} . _(' le poste comptable [') . $poste->id . _('n\'existe pas'), 9);
         }
         /* Check if the card belong to the ledger */
         $fiche = new Fiche($this->db);
         $fiche->get_by_qcode(${'e_march' . $i});
         if ($fiche->belong_ledger($p_jrn, 'cred') != 1) {
             throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'est pas accessible à ce journal'), 10);
         }
         $nb++;
     }
     if ($nb == 0) {
         throw new Exception(_('Il n\'y a aucune marchandise'), 12);
     }
     //------------------------------------------------------
     // The "Paid By"  check
     //------------------------------------------------------
     if ($e_mp != 0) {
         $this->check_payment($e_mp, ${"e_mp_qcode_" . $e_mp});
     }
 }
 /**
  * @brief verify that the operation can be saved
  * @param$p_array array of data same layout that the $_POST from show_form
  *
  *
  * \throw  the getcode  value is 1 incorrect balance,  2 date
  * invalid, 3 invalid amount,  4 the card is not in the range of
  * permitted card, 5 not in the user's period, 6 closed period
  *
  */
 function verify($p_array)
 {
     if (is_array($p_array) == false || empty($p_array)) {
         throw new Exception("Array empty");
     }
     /*
      * Check needed value
      */
     check_parameter($p_array, 'p_jrn,e_date');
     extract($p_array);
     global $g_user;
     $tot_cred = 0;
     $tot_deb = 0;
     $msg = array();
     /* check if we can write into this ledger */
     if ($g_user->check_jrn($p_jrn) != 'W') {
         throw new Exception(_('Accès interdit'), 20);
     }
     /* check for a double reload */
     if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt)) != 0) {
         throw new Exception('Double Encodage', 5);
     }
     // Check the periode and the date
     if (isDate($e_date) == null) {
         throw new Exception('Date invalide', 2);
     }
     $periode = new Periode($this->db);
     /* find the periode  if we have enabled the check_periode */
     if ($this->check_periode() == false) {
         $periode->find_periode($e_date);
     } else {
         $periode->p_id = $period;
         list($min, $max) = $periode->get_date_limit();
         if (cmpDate($e_date, $min) < 0 || cmpDate($e_date, $max) > 0) {
             throw new Exception(_('Date et periode ne correspondent pas'), 6);
         }
     }
     // Periode ferme
     if ($this->is_closed($periode->p_id) == 1) {
         throw new Exception('Periode fermee', 6);
     }
     /* check if we are using the strict mode */
     if ($this->check_strict() == true) {
         /* if we use the strict mode, we get the date of the last
         	  operation */
         $last_date = $this->get_last_date();
         if ($last_date != null && cmpDate($e_date, $last_date) < 0) {
             throw new Exception(_('Vous utilisez le mode strict la dernière operation est la date du ') . $last_date . ' ' . _('vous ne pouvez pas encoder à une date antérieure'), 15);
         }
     }
     for ($i = 0; $i < $nb_item; $i++) {
         $err = 0;
         // Check the balance
         if (!isset(${'amount' . $i})) {
             continue;
         }
         $amount = round(${'amount' . $i}, 2);
         $tot_deb += isset(${'ck' . $i}) ? $amount : 0;
         $tot_cred += !isset(${'ck' . $i}) ? $amount : 0;
         // Check if the card is permitted
         if (isset(${'qc_' . $i}) && trim(${'qc_' . $i}) != "") {
             $f = new Fiche($this->db);
             $f->quick_code = ${'qc_' . $i};
             if ($f->belong_ledger($p_jrn) < 0) {
                 throw new Exception("La fiche quick_code = " . $f->quick_code . " n'est pas dans ce journal", 4);
             }
             if (strlen(trim(${'qc_' . $i})) != 0 && isNumber(${'amount' . $i}) == 0) {
                 throw new Exception('Montant invalide', 3);
             }
             $strPoste = $f->strAttribut(ATTR_DEF_ACCOUNT);
             if ($strPoste == '') {
                 throw new Exception(sprintf(_("La fiche %s n'a pas de poste comptable"), ${"qc_" . $i}));
             }
             $p = new Acc_Account_Ledger($this->db, $strPoste);
             if ($p->do_exist() == 0) {
                 throw new Exception(_('Poste Inexistant pour la fiche [' . ${'qc_' . $i} . ']'), 4);
             }
         }
         // Check if the account is permitted
         if (isset(${'poste' . $i}) && strlen(trim(${'poste' . $i})) != 0) {
             $p = new Acc_Account_Ledger($this->db, ${'poste' . $i});
             if ($p->belong_ledger($p_jrn) < 0) {
                 throw new Exception(_("Le poste") . " " . $p->id . " " . _("n'est pas dans ce journal"), 5);
             }
             if (strlen(trim(${'poste' . $i})) != 0 && isNumber(${'amount' . $i}) == 0) {
                 throw new Exception(_('Poste invalide [' . ${'poste' . $i} . ']'), 3);
             }
             if ($p->do_exist() == 0) {
                 throw new Exception(_('Poste Inexistant [' . ${'poste' . $i} . ']'), 4);
             }
             $card_id = $p->find_card();
             if (!empty($card_id)) {
                 $str_msg = " Le poste " . $p->id . " appartient à " . count($card_id) . " fiche(s) dont :";
                 $max = count($card_id) > MAX_COMPTE_CARD ? MAX_COMPTE_CARD : count($card_id);
                 for ($x = 0; $x < $max; $x++) {
                     $card = new Fiche($this->db, $card_id[$x]['f_id']);
                     $str_msg .= HtmlInput::card_detail($card->strAttribut(ATTR_DEF_QUICKCODE), $card->strAttribut(ATTR_DEF_NAME), 'style="color:red;display:inline;text-decoration:underline"');
                     $str_msg .= " ";
                 }
                 $msg[] = $str_msg;
             }
         }
     }
     $tot_deb = round($tot_deb, 4);
     $tot_cred = round($tot_cred, 4);
     if ($tot_deb != $tot_cred) {
         throw new Exception(_("Balance incorrecte ") . " debit = {$tot_deb} credit={$tot_cred} ", 1);
     }
     return $msg;
 }
 /**
  * Verify that the data are correct before inserting or confirming
  * @brief verify the data 
  * @param an array (usually $_POST)
  * @return String
  * @throw Exception on error occurs
  */
 public function verify($p_array)
 {
     global $g_user;
     if (is_array($p_array) == false || empty($p_array)) {
         throw new Exception("Array empty");
     }
     /*
      * Check needed value
      */
     check_parameter($p_array, 'p_jrn');
     extract($p_array);
     /* check for a double reload */
     if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt)) != 0) {
         throw new Exception(_('Double Encodage'), 5);
     }
     /* check if we can write into this ledger */
     if ($g_user->check_jrn($p_jrn) != 'W') {
         throw new Exception(_('Accès interdit'), 20);
     }
     /* check if there is a bank account linked to the ledger */
     $bank_id = $this->get_bank();
     if ($this->db->count() == 0) {
         throw new Exception("Ce journal n'a pas de compte en banque, allez dans paramètre->journal pour régler cela");
     }
     /* check if the accounting of the bank is correct */
     $fBank = new Fiche($this->db, $bank_id);
     $bank_accounting = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
     if (trim($bank_accounting) == '') {
         throw new Exception('Le poste comptable du compte en banque de ce journal est invalide');
     }
     /* check if the account exists */
     $poste = new Acc_Account_Ledger($this->db, $bank_accounting);
     if ($poste->load() == false) {
         throw new Exception('Le poste comptable du compte en banque de ce journal est invalide');
     }
     if ($chdate != 1 && $chdate != 2) {
         throw new Exception('Le choix de date est invalide');
     }
     if ($chdate == 1) {
         /*  check if the date is valid */
         if (isDate($e_date) == null) {
             throw new Exception('Date invalide', 2);
         }
         $oPeriode = new Periode($this->db);
         if ($this->check_periode() == false) {
             $periode = $oPeriode->find_periode($e_date);
         } else {
             $oPeriode->p_id = $periode;
             list($min, $max) = $oPeriode->get_date_limit();
             if (cmpDate($e_date, $min) < 0 || cmpDate($e_date, $max) > 0) {
                 throw new Exception(_('Date et periode ne correspondent pas'), 6);
             }
         }
         /* check if the periode is closed */
         if ($this->is_closed($periode) == 1) {
             throw new Exception(_('Periode fermee'), 6);
         }
         /* check if we are using the strict mode */
         if ($this->check_strict() == true) {
             /* if we use the strict mode, we get the date of the last
             			operation */
             $last_date = $this->get_last_date();
             if ($last_date != null && cmpDate($e_date, $last_date) < 0) {
                 throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ') . $last_date . _(' vous ne pouvez pas encoder à une date antérieure'), 15);
             }
         }
     }
     $acc_pay = new Acc_Operation($this->db);
     $nb = 0;
     $tot_amount = 0;
     //----------------------------------------
     // foreach item
     //----------------------------------------
     for ($i = 0; $i < $nb_item; $i++) {
         if (strlen(trim(${'e_other' . $i})) == 0) {
             continue;
         }
         /* check if amount are numeric and */
         if (isNumber(${'e_other' . $i . '_amount'}) == 0) {
             throw new Exception('La fiche ' . ${'e_other' . $i} . 'a un montant invalide [' . ${'e_other' . $i . '_amount'} . ']', 6);
         }
         /* compute the total */
         $tot_amount += round(${'e_other' . $i . '_amount'}, 2);
         /* check if all card has a ATTR_DEF_ACCOUNT */
         $fiche = new Fiche($this->db);
         $fiche->get_by_qcode(${'e_other' . $i});
         if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true) {
             throw new Exception('La fiche ' . ${'e_other' . $i} . 'n\'a pas de poste comptable', 8);
         }
         $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
         // if 2 accounts, take only the debit one for customer
         if (strpos($sposte, ',') != 0) {
             $array = explode(',', $sposte);
             $poste_val = $array[1];
         } else {
             $poste_val = $sposte;
         }
         /* The account exists */
         $poste = new Acc_Account_Ledger($this->db, $poste_val);
         if ($poste->load() == false) {
             throw new Exception('Pour la fiche ' . ${'e_other' . $i} . ' le poste comptable [' . $poste->id . 'n\'existe pas', 9);
         }
         /* Check if the card belong to the ledger */
         $fiche = new Fiche($this->db);
         $fiche->get_by_qcode(${'e_other' . $i});
         if ($fiche->belong_ledger($p_jrn, 'deb') != 1) {
             throw new Exception('La fiche ' . ${'e_other' . $i} . 'n\'est pas accessible à ce journal', 10);
         }
         if ($chdate == 2) {
             /*  check if the date is valid */
             if (isDate(${'dateop' . $i}) == null) {
                 throw new Exception('Date invalide', 2);
             }
             $oPeriode = new Periode($this->db);
             if ($this->check_periode() == false) {
                 $periode = $oPeriode->find_periode(${'dateop' . $i});
             } else {
                 $oPeriode->p_id = $periode;
                 list($min, $max) = $oPeriode->get_date_limit();
                 if (cmpDate(${'dateop' . $i}, $min) < 0 || cmpDate(${'dateop' . $i}, $max) > 0) {
                     throw new Exception(_('Date et periode ne correspondent pas'), 6);
                 }
             }
             /* check if the periode is closed */
             if ($this->is_closed($periode) == 1) {
                 throw new Exception(_('Periode fermee'), 6);
             }
             /* check if we are using the strict mode */
             if ($this->check_strict() == true) {
                 /* if we use the strict mode, we get the date of the last
                 	  operation */
                 $last_date = $this->get_last_date();
                 if ($last_date != null && cmpDate(${'dateop' . $i}, $last_date) < 0) {
                     throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ') . $last_date . _(' vous ne pouvez pas encoder à une date antérieure'), 15);
                 }
             }
         }
         $nb++;
     }
     if ($nb == 0) {
         throw new Exception('Il n\'y a aucune opération', 12);
     }
     /* Check if the last_saldo and first_saldo are correct */
     if (strlen(trim($last_sold)) != 0 && isNumber($last_sold) && strlen(trim($first_sold)) != 0 && isNumber($first_sold)) {
         $diff = $last_sold - $first_sold;
         $diff = round($diff, 2) - round($tot_amount, 2);
         if ($first_sold != 0 && $last_sold != 0) {
             if ($diff != 0) {
                 throw new Exception('Le montant de l\'extrait est incorrect' . $tot_amount . ' extrait ' . $diff, 13);
             }
         }
     }
 }