Ejemplo n.º 1
0
 /**
  * @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;
 }
 /**
  * @covers Acc_Account_Ledger::do_exist
  * @todo   Implement testDo_exist().
  * @dataProvider dataDo_exist
  */
 public function testDo_exist($p_value, $result)
 {
     $this->object->id = $p_value;
     $this->assertEquals($this->object->do_exist(), $result);
 }