Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 $sql = $sql . $cond_poste . '  order by pcm_val::text';
 $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>
            $diff = bcsub($op['deb_montant'], $op['cred_montant']);
            $prog = bcadd($prog, $diff);
            echo '"' . $pos['pcm_val'] . '";' . '"' . $op['jr_pj_number'] . '"' . ";" . '"' . $op['jrn_def_code'] . '"' . ";" . '"' . $op['jrn_def_name'] . '"' . ";" . '"' . $name . '";' . '"' . $op['jr_internal'] . '"' . ";" . '"' . $op['j_date_fmt'] . '"' . ";" . '"' . $op['description'] . '";' . nb($op['deb_montant']) . ";" . nb($op['cred_montant']) . ";" . nb(abs($prog)) . ";" . ($op['letter'] != -1 ? strtoupper(base_convert($op['letter'], 10, 36)) : "");
            printf("\n");
        }
        $solde_type = $tot_deb > $tot_cred ? "solde débiteur" : "solde créditeur";
        $diff = abs($tot_deb - $tot_cred);
        printf(";;;" . '"' . _('total') . '";' . '"' . $current_exercice . '";' . '"' . "{$solde_type}" . '"' . ";" . nb($tot_deb) . ";" . nb($tot_cred) . ";" . nb($diff) . ";" . "\n");
    }
} else {
    /* detail of all operation */
    if (count($a_poste) == 0) {
        exit;
    }
    foreach ($a_poste as $pos) {
        $Poste = new Acc_Account_Ledger($cn, $pos['pcm_val']);
        $Poste->get_name();
        list($array, $tot_deb, $tot_cred) = $Poste->get_row_date($_REQUEST['from_periode'], $_REQUEST['to_periode'], $_GET['ople']);
        if (count($Poste->row) == 0) {
            continue;
        }
        echo '"Poste";' . '"Lib.";' . '"QuickCode";' . "\"Code interne\";" . "\"Date\";" . "\"Description\";" . "\"Montant\";" . "\"D/C\"";
        printf("\n");
        foreach ($Poste->row as $a) {
            $op = new Acc_Operation($cn);
            $op->jr_id = $a['jr_id'];
            $result = $op->get_jrnx_detail();
            foreach ($result as $r) {
                printf('"%s";"%s";"%s";"%s";"%s";"%s";"%s";%12.2f;"%s"', $r['j_poste'], $r['pcm_lib'], $r['j_qcode'], $r['jr_internal'], $r['jr_date'], $a['description'], $a['jr_pj_number'], nb($r['j_montant']), $r['debit']);
                printf("\r\n");
            }
Ejemplo n.º 4
0
     $Poste = new Acc_Account_Ledger($cn, $_GET['poste_id']);
     echo Acc_Account_Ledger::HtmlTableHeader();
     foreach ($a_poste as $poste_id) {
         $Poste = new Acc_Account_Ledger($cn, $poste_id['pcm_val']);
         $Poste->HtmlTable(null, $_GET['ople']);
     }
     echo Acc_Account_Ledger::HtmlTableHeader();
     echo "</div>";
 } else {
     //----------------------------------------------------------------------
     // Detail
     //----------------------------------------------------------------------
     echo Acc_Account_Ledger::HtmlTableHeader();
     echo '<table  style="width:100%;margin-left: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'], $_GET['ople']);
         if (empty($Poste->row)) {
             continue;
         }
         echo '<tr><td  class="mtitle" style="width:auto" colspan="6"><h2 class="title">' . $poste_id['pcm_val'] . ' ' . h($Poste->label) . '</h2></td></tr>';
         $detail = $Poste->row[0];
         $old = array();
         foreach ($Poste->row as $detail) {
             /* avoid duplicates */
             if (in_array($detail['jr_id'], $old) == TRUE) {
                 continue;
             }
             $old[] = $detail['jr_id'];
             echo tr(td("Journal :" . $detail['jrn_def_name'], ''), 'style="width:auto" colspan="6"');
Ejemplo n.º 5
0
$pdf->setTitle("Grand Livre", true);
$pdf->SetAuthor('NOALYSS');
if (count($a_poste) == 0) {
    $pdf->Output();
    return;
}
// Header
$header = array("Date", "Référence", "Libellé", "Pièce", "Let", "Débit", "Crédit", "Solde");
// Left or Right aligned
$lor = array("L", "L", "L", "L", "R", "R", "R", "R");
// Column widths (in mm)
$width = array(13, 20, 60, 15, 12, 20, 20, 20);
$l = isset($_REQUEST['letter']) ? 2 : 0;
$s = isset($_REQUEST['solded']) ? 1 : 0;
foreach ($a_poste as $poste) {
    $Poste = new Acc_Account_Ledger($cn, $poste['pcm_val']);
    $array1 = $Poste->get_row_date($from_periode, $to_periode, $l, $s);
    // don't print empty account
    if (count($array1) == 0) {
        continue;
    }
    $array = $array1[0];
    $tot_deb = $array1[1];
    $tot_cred = $array1[2];
    $pdf->SetFont('DejaVuCond', '', 10);
    $Libelle = sprintf("%s - %s ", $Poste->id, $Poste->get_name());
    $pdf->Cell(0, 7, $Libelle, 1, 1, 'C');
    $pdf->SetFont('DejaVuCond', '', 6);
    for ($i = 0; $i < count($header); $i++) {
        $pdf->Cell($width[$i], 4, $header[$i], 0, 0, $lor[$i]);
    }
Ejemplo n.º 6
0
        }
    }
    $sql = $sql . $cond_poste . '  order by pcm_val::text';
    $a_poste = $cn->get_array($sql);
}
if (count($a_poste) == 0) {
    echo 'Rien à rapporter.';
    printf("\n");
    exit;
}
// Header
$header = array("Date", "Référence", "Libellé", "Pièce", "Lettrage", "Débit", "Crédit", "Solde");
$l = isset($_GET['letter']) ? 2 : 0;
$s = isset($_REQUEST['solded']) ? 1 : 0;
foreach ($a_poste as $poste) {
    $Poste = new Acc_Account_Ledger($cn, $poste['pcm_val']);
    $array1 = $Poste->get_row_date($from_periode, $to_periode, $l, $s);
    // don't print empty account
    if (count($array1) == 0) {
        continue;
    }
    $array = $array1[0];
    $tot_deb = $array1[1];
    $tot_cred = $array1[2];
    // don't print empty account
    if (count($array) == 0) {
        continue;
    }
    echo sprintf("%s - %s ", $Poste->id, $Poste->get_name());
    printf("\n");
    for ($i = 0; $i < count($header); $i++) {
}
$ret = "";
$pdf = new PDF($cn);
$pdf->setDossierInfo("  Periode : " . $_GET['from_periode'] . " - " . $_GET['to_periode']);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetAuthor('NOALYSS');
$pdf->setTitle("Détail poste comptable", true);
if (count($a_poste) == 0) {
    $pdf->Output('poste.pdf', 'D');
    exit;
}
$size = array(13, 25, 13, 65, 12, 20, 20, 20);
$align = array('L', 'C', 'C', 'L', 'R', 'R', 'R', 'R');
foreach ($a_poste as $poste) {
    $Poste = new Acc_Account_Ledger($cn, $poste['pcm_val']);
    list($array, $tot_deb, $tot_cred) = $Poste->get_row_date($from_periode, $to_periode, $_GET['ople']);
    // don't print empty account
    if (count($array) == 0) {
        continue;
    }
    $Libelle = sprintf("(%s) %s ", $Poste->id, $Poste->get_name());
    $pdf->SetFont('DejaVuCond', '', 10);
    $pdf->Cell(0, 8, $Libelle, 1, 0, 'C');
    $pdf->Ln();
    $pdf->SetFont('DejaVuCond', '', 8);
    $l = 0;
    $pdf->Cell($size[$l], 6, 'Date', 0, 0, 'L');
    $l++;
    $pdf->Cell($size[$l], 6, 'Ref', 0, 0, 'C');
    $l++;
 static function test_me()
 {
     $cn = new Database(dossier::id());
     $a = new Acc_Account_Ledger($cn, 550);
     echo ' Journal 4 ' . $a->belong_ledger(4);
     return $a->belong_ledger(4);
 }
Ejemplo n.º 9
0
        $detail_card = HtmlInput::card_detail($fiche->strAttribut(ATTR_DEF_QUICKCODE), $fiche->getName());
        echo h2($fiche->getName() . '[' . $fiche->strAttribut(ATTR_DEF_QUICKCODE) . ']', ' class="title" ');
        echo '<p style="text-align:center;">' . $detail_card . '</p>';
        if ($fiche->HtmlTable($array, 0, $from_div) == -1) {
            echo h2(_("Aucune opération pour l'exercice courant"), 'class="error"');
        }
        echo $old;
        $html = ob_get_contents();
        ob_end_clean();
    }
}
///////////////////////////////////////////////////////////////////////////
// for an account
///////////////////////////////////////////////////////////////////////////
if (isset($_REQUEST['pcm_val'])) {
    $poste = new Acc_Account_Ledger($cn, $_REQUEST['pcm_val']);
    $year = $g_user->get_exercice();
    if ($year == 0) {
        $html = _("erreur aucune période par défaut, allez dans préférence pour en choisir une");
    } else {
        $exercice = new Exercice($cn);
        $old = '';
        $per = new Periode($cn);
        $limit_periode = $per->get_limit($year);
        $array['from_periode'] = $limit_periode[0]->first_day();
        $array['to_periode'] = $limit_periode[1]->last_day();
        if (isset($_GET['ex'])) {
            $limit_periode = $per->get_limit($_GET['ex']);
            if ($_GET['ex'] < $year) {
                $array['from_periode'] = $limit_periode[0]->first_day();
            } else {
Ejemplo n.º 10
0
 static function parse_formula($p_cn, $p_label, $p_formula, $p_start, $p_end, $p_eval = true, $p_type_date = 0, $p_sql = "")
 {
     global $g_user;
     if (Impress::check_formula($p_formula) == false) {
         if ($p_eval == true) {
             return array('desc' => $p_label . '  Erreur Formule!', 'montant' => 0);
         } else {
             return $p_formula;
         }
     }
     if ($p_type_date == 0) {
         $cond = sql_filter_per($p_cn, $p_start, $p_end, 'p_id', 'j_tech_per');
     } else {
         $cond = "( j_date >= to_date('{$p_start}','DD.MM.YYYY') and j_date <= to_date('{$p_end}','DD.MM.YYYY'))";
     }
     include_once "class_acc_account_ledger.php";
     while (preg_match_all("(\\[[0-9]*[A-Z]*%*c*d*s*\\])", $p_formula, $e) == true) {
         // remove the [ ]
         $x = $e[0];
         foreach ($x as $line) {
             $compute = 'all';
             if (strpos($line, 'd') != 0) {
                 $compute = 'deb';
             }
             if (strpos($line, 'c') != 0) {
                 $compute = 'cred';
             }
             if (strpos($line, 's') != 0) {
                 $compute = 'signed';
             }
             $line = str_replace("[", "", $line);
             $line = str_replace("]", "", $line);
             $line = str_replace("d", "", $line);
             $line = str_replace("c", "", $line);
             $line = str_replace("s", "", $line);
             // If there is a FROM clause we must recompute
             // the time cond
             if ($p_type_date == 0 && preg_match("/FROM=[0-9]+\\.[0-9]+/", $p_formula, $afrom) == 1) {
                 // There is a FROM clause
                 // then we must modify the cond for the periode
                 $from = str_replace("FROM=", "", $afrom[0]);
                 // Get the periode
                 /*! \note special value for the clause FROM=00.0000
                  */
                 if ($from == '00.0000') {
                     // retrieve the first month of this periode
                     $user_periode = $g_user->get_periode();
                     $oPeriode = new Periode($p_cn);
                     $periode = $oPeriode->get_exercice($user_periode);
                     list($first, $last) = $oPeriode->get_limit($periode);
                     $ret = $first->get_date_limit();
                     $end_date = $oPeriode->get_date_limit($p_end);
                     if ($ret == null) {
                         throw new Exception('Pas de limite à cette période', 1);
                     }
                     $cond = sql_filter_per($p_cn, $ret['p_start'], $end_date['p_end'], 'date', 'j_tech_per');
                 } else {
                     $oPeriode = new Periode($p_cn);
                     try {
                         $pfrom = $oPeriode->find_periode('01.' . $from);
                         $cond = sql_filter_per($p_cn, $pfrom, $p_end, 'p_id', 'j_tech_per');
                     } catch (Exception $exp) {
                         /* if none periode is found
                               then we take the first periode of the year
                            */
                         $user_periode = $g_user->get_periode();
                         $year = $oPeriode->get_exercice($user_periode);
                         list($first, $last) = $oPeriode->get_limit($year);
                         $ret = $first->get_date_limit();
                         $end_date = $oPeriode->get_date_limit($p_end);
                         if ($ret == null) {
                             throw new Exception('Pas de limite à cette période', 1);
                         }
                         $cond = sql_filter_per($p_cn, $ret['p_start'], $end_date['p_end'], 'date', 'j_tech_per');
                     }
                 }
             }
             if (strpos($p_formula, "FROM") != 0) {
                 // We remove FROM out of the p_formula
                 $p_formula = substr_replace($p_formula, "", strpos($p_formula, "FROM"));
             }
             // Get sum of account
             $P = new Acc_Account_Ledger($p_cn, $line);
             $detail = $P->get_solde_detail($cond . $p_sql);
             if ($compute == 'all') {
                 $i = $detail['solde'];
             }
             if ($compute == 'deb') {
                 $i = $detail['debit'];
             }
             if ($compute == 'cred') {
                 $i = $detail['credit'];
             }
             if ($compute == 'signed') {
                 $i = $detail['debit'] - $detail['credit'];
             }
             $p_formula = str_replace($x[0], $i, $p_formula);
         }
     }
     // $p_eval is true then we eval and returns result
     if ($p_eval == true) {
         $p_formula = "\$result=" . $p_formula . ";";
         eval("{$p_formula}");
         while (preg_match("/\\[([0-9]+)([Tt]*)\\]/", trim($p_label), $e) == 1) {
             $nom = "!!" . $e[1] . "!!";
             if (Impress::check_formula($e[0])) {
                 $nom = $p_cn->get_value("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE pcm_val::text LIKE \$1||'%' ORDER BY pcm_val ASC LIMIT 1", array($e[1]));
                 if ($nom) {
                     if ($e[2] == 'T') {
                         $nom = strtoupper($nom);
                     }
                     if ($e[2] == 't') {
                         $nom = strtolower($nom);
                     }
                 }
             }
             $p_label = str_replace($e[0], $nom, $p_label);
         }
         $aret = array('desc' => $p_label, 'montant' => $result);
         return $aret;
     } else {
         // $p_eval is false we returns only the string
         return $p_formula;
     }
 }
 /**
  * @covers Acc_Account_Ledger::test_me
  * @todo   Implement testTest_me().
  */
 public function testTest_me()
 {
     $this->assertEquals($this->object->test_me(), 0);
 }
Ejemplo n.º 12
0
 $r .= ob_get_contents();
 ob_end_clean();
 $r .= dossier::hidden();
 $r .= isset($c) ? HtmlInput::hidden('account', $c) : "";
 $r .= isset($l) ? HtmlInput::hidden('label', $l) : "";
 $r .= isset($j) ? HtmlInput::hidden('jrn', $j) : "";
 $r .= isset($nover) ? HtmlInput::hidden('nover', '1') : "";
 $r .= isset($nosearch) ? HtmlInput::hidden('nosearch', '1') : "";
 $r .= isset($bracket) ? HtmlInput::hidden('bracket', '1') : "";
 $r .= '</form>';
 $sql = "\n\t\tselect pcm_val,pcm_lib,array_to_string(array_agg(j_qcode) , ',') as acode\n\t\tfrom tmp_pcmn left join vw_poste_qcode on (j_poste=pcm_val) ";
 $sep = " where ";
 /* build the sql stmt */
 if (isset($j) && $j > 0 && isNumber($j)) {
     /* create a filter on the ledger */
     $ledger = new Acc_Account_Ledger($cn, 0);
     $fd_id = $ledger->build_sql_account($j);
     if ($fd_id != '') {
         $sql .= " {$sep} (" . $fd_id . ')';
         $sep = " and ";
     }
 }
 /* show result */
 if (isset($q) && strlen(trim($q)) > 0) {
     $q = sql_string($q);
     $sql .= sprintf(" {$sep} ( pcm_val::text like '%s%%' or pcm_lib::text ilike '%%%s%%') ", $q, $q);
 }
 $sql .= ' group by pcm_val,pcm_lib,pcm_val_parent, pcm_type  order by pcm_val::text limit 50';
 if (isset($q) && strlen(trim($q)) > 0) {
     $array = $cn->get_array($sql);
 }
Ejemplo n.º 13
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});
     }
 }
Ejemplo n.º 14
0
 /**
  * @brief check and warn if an accound has the wrong saldo
  * @param $p_message legend of the fieldset
  * @param $p_type type of the Acccount ACT actif, ACTINV...
  * @param $p_type the saldo must debit or credit
  */
 private function warning($p_message, $p_type, $p_deb)
 {
     $sql = "select pcm_val,pcm_lib from tmp_pcmn where pcm_type='{$p_type}'";
     $res = $this->db->exec_sql($sql);
     if (Database::num_row($res) == 0) {
         return;
     }
     $count = 0;
     $nRow = Database::num_row($res);
     $ret = "";
     $obj = new Acc_Account_Ledger($this->db, 0);
     for ($i = 0; $i < $nRow; $i++) {
         $line = Database::fetch_array($res, $i);
         /* set the periode filter */
         $sql = sql_filter_per($this->db, $this->from, $this->to, 'p_id', 'j_tech_per');
         $obj->id = $line['pcm_val'];
         $solde = $obj->get_solde_detail($sql);
         $solde_signed = bcsub($solde['debit'], $solde['credit']);
         if ($solde_signed < 0 && $p_deb == 'D' || $solde_signed > 0 && $p_deb == 'C') {
             $ret .= '<li> ' . HtmlInput::history_account($line['pcm_val'], 'Anomalie pour le compte ' . $line['pcm_val'] . ' ' . h($line['pcm_lib']) . "  D: " . $solde['debit'] . "  C: " . $solde['credit'] . " diff " . $solde['solde']);
             $count++;
         }
     }
     echo '<fieldset>';
     echo '<legend>' . $p_message . '</legend>';
     if ($count != 0) {
         echo '<ol>' . $ret . '</ol>';
         echo '<span class="error">' . _("Nbres anomalies") . ' : ' . $count . '</span>';
     } else {
         echo _("Pas d'anomalie détectée");
     }
     echo '</fieldset>';
 }
Ejemplo n.º 15
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);
         }
     }
 }
Ejemplo n.º 16
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);
     }
 }
Ejemplo n.º 17
0
 public function insert($p_array = null)
 {
     global $g_parameter;
     bcscale(2);
     $internal_code = "";
     $oid = 0;
     extract($p_array);
     $ret = '';
     // Debit = banque
     $bank_id = $this->get_bank();
     $fBank = new Fiche($this->db, $bank_id);
     $e_bank_account = $fBank->strAttribut(ATTR_DEF_QUICKCODE);
     // Get the saldo
     $pPeriode = new Periode($this->db);
     $sposte = $fBank->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;
     }
     $acc_account = new Acc_Account_Ledger($this->db, $poste_val);
     // If date = deposit date
     if ($chdate == 1) {
         if ($this->check_periode() == true) {
             $pPeriode->p_id = $periode;
         } else {
             $pPeriode->find_periode($e_date);
         }
         $exercice = $pPeriode->get_exercice();
         $filter_year = "  j_tech_per in (select p_id from parm_periode where  p_exercice='" . $exercice . "')";
         $asolde = $acc_account->get_solde_detail($filter_year);
         $deb = $asolde['debit'];
         $cred = $asolde['credit'];
         $solde = bcsub($deb, $cred);
         $new_solde = $solde;
     }
     try {
         $this->db->start();
         $amount = 0.0;
         $idx_operation = 0;
         $ret = '<table class="result" >';
         $ret .= tr(th('Date') . th('n° interne') . th('Quick Code') . th('Nom') . th('Libellé') . th('Montant', ' style="text-align:right"'));
         // Credit = goods
         $get_solde = true;
         for ($i = 0; $i < $nb_item; $i++) {
             // insert it into the database
             // and quit the loop ?
             if (strlen(trim(${"e_other{$i}"})) == 0) {
                 continue;
             }
             if ($chdate == 2) {
                 $e_date = ${'dateop' . $i};
             }
             // if date is date of operation
             if ($chdate == 2 && $get_solde) {
                 $get_solde = false;
                 if ($this->check_periode() == true) {
                     $pPeriode->p_id = $periode;
                 } else {
                     $pPeriode->find_periode($e_date);
                 }
                 $exercice = $pPeriode->get_exercice();
                 $filter_year = "  j_tech_per in (select p_id from parm_periode where  p_exercice='" . $exercice . "')";
                 $solde = $acc_account->get_solde($filter_year);
                 $new_solde = $solde;
             }
             $fPoste = new Fiche($this->db);
             $fPoste->get_by_qcode(${"e_other{$i}"});
             // round it
             ${"e_other{$i}" . "_amount"} = round(${"e_other{$i}" . "_amount"}, 2);
             $amount += ${"e_other{$i}" . "_amount"};
             // Record a line for the bank
             // Compute the j_grpt
             $seq = $this->db->get_next_seq('s_grpt');
             $acc_operation = new Acc_Operation($this->db);
             $acc_operation->date = $e_date;
             $sposte = $fPoste->strAttribut(ATTR_DEF_ACCOUNT);
             // if 2 accounts
             if (strpos($sposte, ',') != 0) {
                 $array = explode(',', $sposte);
                 if (${"e_other{$i}" . "_amount"} < 0) {
                     $poste_val = $array[1];
                 } else {
                     $poste_val = $array[0];
                 }
             } else {
                 $poste_val = $sposte;
             }
             $acc_operation->poste = $poste_val;
             $acc_operation->amount = ${"e_other{$i}" . "_amount"} * -1;
             $acc_operation->grpt = $seq;
             $acc_operation->jrn = $p_jrn;
             $acc_operation->type = 'd';
             if (isset($periode)) {
                 $tperiode = $periode;
             } else {
                 $per = new Periode($this->db);
                 $tperiode = $per->find_periode($e_date);
             }
             $acc_operation->periode = $tperiode;
             $acc_operation->qcode = ${"e_other" . $i};
             $j_id = $acc_operation->insert_jrnx();
             $acc_operation = new Acc_Operation($this->db);
             $acc_operation->date = $e_date;
             $sposte = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
             // if 2 accounts
             if (strpos($sposte, ',') != 0) {
                 $array = explode(',', $sposte);
                 if (${"e_other{$i}" . "_amount"} < 0) {
                     $poste_val = $array[1];
                 } else {
                     $poste_val = $array[0];
                 }
             } else {
                 $poste_val = $sposte;
             }
             $acc_operation->poste = $poste_val;
             $acc_operation->amount = ${"e_other{$i}" . "_amount"};
             $acc_operation->grpt = $seq;
             $acc_operation->jrn = $p_jrn;
             $acc_operation->type = 'd';
             $acc_operation->periode = $tperiode;
             $acc_operation->qcode = $e_bank_account;
             $acc_operation->insert_jrnx();
             if (sql_string(${"e_other{$i}" . "_comment"}) == null) {
                 // if comment is blank set a default one
                 $comment = "  compte : " . $fBank->strAttribut(ATTR_DEF_NAME) . ' a ' . $fPoste->strAttribut(ATTR_DEF_NAME);
             } else {
                 $comment = ${'e_other' . $i . '_comment'};
             }
             $acc_operation = new Acc_Operation($this->db);
             $acc_operation->jrn = $p_jrn;
             $acc_operation->amount = abs(${"e_other{$i}" . "_amount"});
             $acc_operation->date = $e_date;
             $acc_operation->desc = $comment;
             $acc_operation->grpt = $seq;
             $acc_operation->periode = $tperiode;
             $acc_operation->mt = $mt;
             $idx_operation++;
             $acc_operation->pj = '';
             if (trim($e_pj) != '' && $this->numb_operation() == true) {
                 $acc_operation->pj = $e_pj . str_pad($idx_operation, 3, 0, STR_PAD_LEFT);
             }
             if (trim($e_pj) != '' && $this->numb_operation() == false) {
                 $acc_operation->pj = $e_pj;
             }
             $jr_id = $acc_operation->insert_jrn();
             // 	  $acc_operation->set_pj();
             $this->db->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj, $jr_id));
             $internal = $this->compute_internal_code($seq);
             if (trim(${"e_concerned" . $i}) != "") {
                 if (strpos(${"e_concerned" . $i}, ',') != 0) {
                     $aRapt = explode(',', ${"e_concerned" . $i});
                     foreach ($aRapt as $rRapt) {
                         // Add a "concerned operation to bound these op.together
                         //
                         $rec = new Acc_Reconciliation($this->db);
                         $rec->set_jr_id($jr_id);
                         if (isNumber($rRapt) == 1) {
                             $rec->insert($rRapt);
                         }
                     }
                 } else {
                     if (isNumber(${"e_concerned" . $i}) == 1) {
                         $rec = new Acc_Reconciliation($this->db);
                         $rec->set_jr_id($jr_id);
                         $rec->insert(${"e_concerned{$i}"});
                     }
                 }
             }
             // Set Internal code
             $this->grpt_id = $seq;
             /**
              * save also into quant_fin
              */
             $this->insert_quant_fin($fBank->id, $jr_id, $fPoste->id, ${"e_other{$i}" . "_amount"});
             if ($g_parameter->MY_ANALYTIC != "nu") {
                 // for each item, insert into operation_analytique */
                 $op = new Anc_Operation($this->db);
                 $op->oa_group = $this->db->get_next_seq("s_oa_group");
                 /* for analytic */
                 $op->j_id = $j_id;
                 $op->oa_date = $e_date;
                 $op->oa_debit = 'f';
                 $op->oa_description = sql_string($comment);
                 $op->save_form_plan($_POST, $i, $j_id);
             }
             $this->update_internal_code($internal);
             $js_detail = HtmlInput::detail_op($jr_id, $internal);
             // Compute display
             $row = td($e_date) . td($js_detail) . td(${"e_other{$i}"}) . td($fPoste->strAttribut(ATTR_DEF_NAME)) . td(${"e_other" . $i . "_comment"}) . td(nbm(${"e_other{$i}" . "_amount"}), 'class="num"');
             $class = $i % 2 == 0 ? ' class="even" ' : ' class="odd" ';
             $ret .= tr($row, $class);
             if ($i == 0) {
                 // first record we upload the files and
                 // keep variable to update other row of jrn
                 if (isset($_FILES)) {
                     $oid = $this->db->save_upload_document($seq);
                 }
             } else {
                 if ($oid != 0) {
                     $this->db->exec_sql("update jrn set jr_pj=\$1 , jr_pj_name=\$2,\n                                            jr_pj_type=\$3  where jr_grpt_id=\$4", array($oid, $_FILES['pj']['name'], $_FILES['pj']['type'], $seq));
                 }
             }
         }
         // for nbitem
         // increment pj
         if (strlen(trim($e_pj)) != 0) {
             $this->inc_seq_pj();
         }
         $ret .= '</table>';
     } catch (Exception $e) {
         $r = '<span class="error">' . 'Erreur dans l\'enregistrement ' . __FILE__ . ':' . __LINE__ . ' ' . $e->getMessage();
         $this->db->rollback();
         throw new Exception($r);
     }
     $this->db->commit();
     $r = "";
     $r .= "<br>Ancien solde " . nbm($solde);
     $new_solde = bcadd($new_solde, $amount);
     $r .= "<br>Nouveau solde " . nbm($new_solde);
     $ret .= $r;
     return $ret;
 }