Exemplo 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;
 }
Exemplo n.º 2
0
 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});
     }
 }
Exemplo n.º 3
0
 function HtmlTable($p_array = null, $op_let = 0, $from_div = 1)
 {
     if ($p_array == null) {
         $p_array = $_REQUEST;
     }
     $progress = 0;
     // if from_periode is greater than to periode then swap the values
     if (cmpDate($p_array['from_periode'], $p_array['to_periode']) > 0) {
         $tmp = $p_array['from_periode'];
         $p_array['from_periode'] = $p_array['to_periode'];
         $p_array['to_periode'] = $tmp;
     }
     list($array, $tot_deb, $tot_cred) = $this->get_row_date($p_array['from_periode'], $p_array['to_periode'], $op_let);
     if (count($this->row) == 0) {
         return -1;
     }
     $rep = "";
     if ($from_div == 1) {
         echo "<TABLE class=\"resultfooter\" style=\"margin:1%;width:98%;;border-collapse:separate;border-spacing:0px 5px\">";
     } else {
         echo "<TABLE id=\"tb" . $from_div . "\"class=\"result\" style=\"margin:1%;width:98%;border-collapse:separate;border-spacing:0px 2px\">";
     }
     echo '<tbody>';
     echo "<TR>" . "<TH style=\"text-align:left\">" . _('Date') . "</TH>" . "<TH style=\"text-align:left\">" . _('n° pièce') . " </TH>" . "<TH style=\"text-align:left\">" . _('Code interne') . " </TH>" . "<TH style=\"text-align:left\">" . _('Description') . " </TH>" . "<TH style=\"text-align:right\">" . _('Débit') . "  </TH>" . "<TH style=\"text-align:right\">" . _('Crédit') . " </TH>" . th('Prog.', 'style="text-align:right"') . th('Let.', 'style="text-align:right"');
     "</TR>";
     $old_exercice = "";
     $sum_deb = 0;
     $sum_cred = 0;
     bcscale(2);
     $idx = 0;
     foreach ($this->row as $op) {
         $vw_operation = sprintf('<A class="detail" style="text-decoration:underline;color:red" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s</A>', $op['jr_id'], dossier::id(), $op['jr_internal']);
         $let = '';
         $html_let = "";
         if ($op['letter'] != -1) {
             $let = strtoupper(base_convert($op['letter'], 10, 36));
             $html_let = HtmlInput::show_reconcile($from_div, $let);
         }
         $tmp_diff = bcsub($op['deb_montant'], $op['cred_montant']);
         /*
          * reset prog. balance to zero if we change of exercice
          */
         if ($old_exercice != $op['p_exercice']) {
             if ($old_exercice != '') {
                 $progress = bcsub($sum_deb, $sum_cred);
                 $side = "&nbsp;" . $this->get_amount_side($progress);
                 echo "<TR class=\"highlight\">" . "<TD>{$old_exercice}</TD>" . td('') . "<TD></TD>" . "<TD>Totaux</TD>" . "<TD style=\"text-align:right\">" . nbm($sum_deb) . "</TD>" . "<TD style=\"text-align:right\">" . nbm($sum_cred) . "</TD>" . td(nbm(abs($progress)) . $side, 'style="text-align:right"') . td('') . "</TR>";
                 $sum_cred = 0;
                 $sum_deb = 0;
                 $progress = 0;
             }
         }
         $progress = bcadd($progress, $tmp_diff);
         $side = "&nbsp;" . $this->get_amount_side($progress);
         $sum_cred = bcadd($sum_cred, $op['cred_montant']);
         $sum_deb = bcadd($sum_deb, $op['deb_montant']);
         if ($idx % 2 == 0) {
             $class = 'class="odd"';
         } else {
             $class = ' class="even"';
         }
         $idx++;
         echo "<TR {$class} name=\"tr_" . $let . "_" . $from_div . "\">" . "<TD>" . smaller_date(format_date($op['j_date_fmt'])) . "</TD>" . td(h($op['jr_pj_number'])) . "<TD>" . $vw_operation . "</TD>" . "<TD>" . h($op['description']) . "</TD>" . "<TD style=\"text-align:right\">" . nbm($op['deb_montant']) . "</TD>" . "<TD style=\"text-align:right\">" . nbm($op['cred_montant']) . "</TD>" . td(nbm(abs($progress)) . $side, 'style="text-align:right"') . td($html_let, ' style="text-align:right"') . "</TR>";
         $old_exercice = $op['p_exercice'];
     }
     $solde_type = $sum_deb > $sum_cred ? "solde débiteur" : "solde créditeur";
     $diff = abs(bcsub($sum_deb, $sum_cred));
     echo '<tfoot>';
     echo "<TR class=\"highlight\">" . "<TD>Totaux</TD>" . "<TD ></TD>" . "<TD ></TD>" . "<TD></TD>" . "<TD  style=\"text-align:right\">" . nbm($sum_deb) . "</TD>" . "<TD  style=\"text-align:right\">" . nbm($sum_cred) . "</TD>" . "<TD style=\"text-align:right\">" . nbm($diff) . "</TD>" . "</TR>";
     echo "<TR style=\"font-weight:bold\">" . "<TD>{$solde_type}</TD>" . "<TD style=\"text-align:right\">" . nbm($diff) . "</TD>" . "<TD></TD>" . "</TR>";
     echo '</tfoot>';
     echo '</tbody>';
     echo "</table>";
     return 0;
 }
Exemplo n.º 4
0
 /**
  * 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);
             }
         }
     }
 }