Exemplo n.º 1
0
 function save()
 {
     // if p_code=="" nothing to save
     if ($this->p_code == -1) {
         return;
     }
     // check if the account exists
     $acc = new Acc_Account_Ledger($this->db, $this->p_value);
     if ($acc->load() == false) {
         alert(_("Ce compte n'existe pas"));
     } else {
         $this->p_comment = sql_string($this->p_comment);
         $this->p_value = sql_string($this->p_value);
         $this->p_code = sql_string($this->p_code);
         $sql = "update parm_code set " . "p_comment='" . $this->p_comment . "'  " . ",p_value='" . $this->p_value . "'  " . "where p_code='" . $this->p_code . "'";
         $Res = $this->db->exec_sql($sql);
     }
 }
 $a_poste = $cn->get_array($sql);
 if (sizeof($a_poste) == 0) {
     die("Nothing here. Strange.");
     exit;
 }
 if (isDate($_REQUEST['from_periode']) == null || isDate($_REQUEST['to_periode']) == null) {
     echo alert('Date malformée, désolée');
     return;
 }
 echo '<div class="content">';
 echo '<table class="result">';
 $l = isset($_REQUEST['letter']) ? 2 : 0;
 $s = isset($_REQUEST['solded']) ? 1 : 0;
 foreach ($a_poste as $poste_id) {
     $Poste = new Acc_Account_Ledger($cn, $poste_id['pcm_val']);
     $Poste->load();
     $Poste->get_row_date($_GET['from_periode'], $_GET['to_periode'], $l, $s);
     if (empty($Poste->row)) {
         continue;
     }
     echo '<tr >
     <td colspan="8" style="width:auto">
     <h2 class="info">' . $poste_id['pcm_val'] . ' ' . h($Poste->label) . '</h2>
     </td>
     </tr>';
     echo '<tr>
     <td>Date</td>
     <td>R&eacute;f&eacute;rence</td>
     <td>Libell&eacute;</td>
     <td>Pi&egrave;ce</td>
     <td align="right">D&eacute;bit</td>
Exemplo n.º 3
0
 /**
  * @brief check if the payment method is valid
  * @param$e_mp is the value and $e_mp_qcode is the quickcode
  * \return nothing throw an Exception
  */
 public function check_payment($e_mp, $e_mp_qcode)
 {
     /*   Check if the "paid by" is empty, */
     if ($e_mp != 0) {
         /* the paid by is not empty then check if valid */
         $empl = new Fiche($this->db);
         $empl->get_by_qcode($e_mp_qcode);
         if ($empl->empty_attribute(ATTR_DEF_ACCOUNT) == true) {
             throw new Exception(_("Celui qui paie n' a pas de poste comptable"), 20);
         }
         /* get the account and explode if necessary */
         $sposte = $empl->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;
         }
         $poste = new Acc_Account_Ledger($this->db, $poste_val);
         if ($poste->load() == false) {
             throw new Exception(sprintf(_("Pour la fiche %s le poste comptable [%s] n'existe pas"), $empl->quick_code, $poste->id), 9);
         }
     }
 }
 /**
  * @covers Acc_Account_Ledger::load
  * @todo   Implement testLoad().
  */
 public function testLoad()
 {
     $this->object->load();
 }
Exemplo n.º 5
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.º 6
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);
             }
         }
     }
 }