noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 04/12: Task #0002125: Contact , devrait être


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 04/12: Task #0002125: Contact , devrait être refait sur le modèle de Fiche->résumé
Date: Sat, 17 Sep 2022 08:40:57 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 8fdd7be647e1200f2efb49456c37d7b214420b7a
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Wed Sep 14 16:27:53 2022 +0200

    Task #0002125: Contact , devrait être refait sur le modèle de Fiche->résumé
---
 include/category_card.inc.php            |  28 ++--
 include/class/card_property.class.php    |   1 +
 include/class/contact.class.php          | 216 ++++++++++++++++++-------------
 include/class/follow_up.class.php        |   6 +-
 include/constant.php                     |   2 +-
 include/contact.inc.php                  |  17 ++-
 include/database/v_contact_sql.class.php |  88 +++++++++++++
 include/lib/data_sql.class.php           |  10 ++
 include/sql/patch/upgrade177.sql         |  25 ++++
 include/template/contact-summary.php     |  96 ++++++++++++++
 sql/upgrade.sql                          | 171 ------------------------
 unit-test/include/class/contactTest.php  | 132 ++++++++++++++++---
 12 files changed, 488 insertions(+), 304 deletions(-)

diff --git a/include/category_card.inc.php b/include/category_card.inc.php
index d91537fc6..018adecd0 100644
--- a/include/category_card.inc.php
+++ b/include/category_card.inc.php
@@ -70,15 +70,21 @@ $f=new Fiche($cn, $f_id);
 
 echo '<div class="content">';
 echo $f->get_gestion_title();
-$menu=array(
-    array('href'=>$root."&sc=dc", 'label'=>_('Fiche'), 'alt'=>_('Détail de la 
fiche')),
-    array('href'=>$root.'&sc=sv', 'label'=>_('Suivi'), 'alt'=>_('Suivi 
Fournisseur, client, banque, devis, bon de commande, courrier')),
-    array('href'=>$root.'&sc=cn', 'label'=>_('Contact'), 'alt'=>_('Liste de 
contacts')),
-    array('href'=>$root.'&sc=op', 'label'=>_('Opérations'), 'alt'=>_('Toutes 
les opérations')),
-    array('href'=>$root.'&sc=bal', 'label'=>_('Balance'), 'alt'=>_('Balance du 
tiers')),
-    array('href'=>$root.'&sc=balag', 'label'=>_('Balance âgée'), 
'alt'=>_('Balance âgée du tiers')),
-    array('href'=>$root.'&sc=let', 'label'=>_('Lettrage'), 
'alt'=>_('Opérations & Lettrages'))
-);
+
+$from=$http->request("ac");
+
+
+$menu[]=    array('href'=>$root."&sc=dc", 'label'=>_('Fiche'), 
'alt'=>_('Détail de la fiche'));
+$menu[]=array('href'=>$root.'&sc=sv', 'label'=>_('Suivi'), 'alt'=>_('Suivi 
Fournisseur, client, banque, devis, bon de commande, courrier'));
+// No submenu CONTACT for the menu CONTACT
+if ( strpos($from,"CONTACT") === false) {
+    $menu[]=array('href'=>$root.'&sc=cn', 'label'=>_('Contact'), 
'alt'=>_('Liste de contacts'));
+}
+$menu[]=array('href'=>$root.'&sc=op', 'label'=>_('Opérations'), 
'alt'=>_('Toutes les opérations'));
+$menu[]=array('href'=>$root.'&sc=bal', 'label'=>_('Balance'), 
'alt'=>_('Balance du tiers'));
+$menu[]=array('href'=>$root.'&sc=balag', 'label'=>_('Balance âgée'), 
'alt'=>_('Balance âgée du tiers'));
+$menu[]=array('href'=>$root.'&sc=let', 'label'=>_('Lettrage'), 
'alt'=>_('Opérations & Lettrages'));
+
 echo '<ul class="tabs" style="padding-top:0px">';
 for ($i=0; $i<count($menu); $i++)
 {
@@ -141,8 +147,8 @@ if ($ss_action=='cn')
     echo dossier::hidden();
     $f=new Fiche($cn, $http->request('f_id','number'));
     $contact=new Contact($cn);
-    $contact->company=$f->get_quick_code();
-    echo $contact->summary("");
+    $contact->filter_company($f->get_quick_code());
+    echo $contact->summary();
 
     $sql=' select fd_id from fiche_def where frd_id='.FICHE_TYPE_CONTACT;
     $filter=$cn->make_list($sql);
diff --git a/include/class/card_property.class.php 
b/include/class/card_property.class.php
index ff267ee37..77b230122 100644
--- a/include/class/card_property.class.php
+++ b/include/class/card_property.class.php
@@ -616,4 +616,5 @@ class Card_Property
         return;
     }
 
+
 }
diff --git a/include/class/contact.class.php b/include/class/contact.class.php
index f45392c4e..8eb1808bd 100644
--- a/include/class/contact.class.php
+++ b/include/class/contact.class.php
@@ -29,118 +29,148 @@ require_once NOALYSS_INCLUDE.'/lib/user_common.php';
 
 class contact extends Fiche
 {
-    var $company; /*!< $company company of the contact 
(ad_id=ATTR_DEF_COMPANY)*/
+    private $filter;
+
     /*!\brief constructor */
     function __construct($p_cn,$p_id=0)
     {
         $this->fiche_def_ref=FICHE_TYPE_CONTACT;
         parent::__construct($p_cn,$p_id) ;
-        $this->company="";
+        $this->filter=[];
     }
-    /*!   
-     * @brief display a summary of the contact card
-     
+
+    /**
+     * @brief Build the SQL query thanks the parameter
+     * @param array $array if empty , we use $this->filter , otherwise $array 
will override it
+     * @return string
+     */
+    function build_sql($array)
+    {
+        if ( empty($array) ) $array=$this->filter;
+
+        $sql_query='
+        SELECT f_id,
+               contact_fname, 
+               contact_name, 
+               contact_qcode, 
+               contact_company, 
+               contact_mobile, 
+               contact_phone, 
+               contact_email, 
+               contact_fax
+        FROM public.v_contact
+        ';
+        $where=' where ';$and='';
+        if ( isset ($array['company'])) {
+            $sql_query.=$where.sprintf(" contact_company ilike '%%%s%%'",
+                    sql_string($array['company']));
+            $where='';$and=' and ';
+        }
+        if ( isset($array['search'])) {
+            $sql_query.=$where.$and.sprintf(" f_id in (select distinct f_id 
from fiche_detail where ad_value ilike '%%%s%%')",
+                    sql_string($array['search']));
+            $where='';$and=' and ';
+
+        }
+        if ( isset($array['category'])) {
+            $sql_query.=$where.$and.sprintf(" fd_id = %s",
+                    sql_string($array['category']));
+            $where='';$and=' and ';
+        }
+
+        return $sql_query;
+    }
+
+    function filter_category($pn_category) {
+        unset($this->filter['category']);
+        if ( !empty($pn_category)
+            && isNumber($pn_category)==1
+            && $pn_category != -1){
+            $this->filter['category']=$pn_category;
+        }
+    }
+    function filter_company($p_company=null) {
+        unset($this->filter['company']);
+        if ( ! empty($p_company) && $p_company != "-1")  {
+            $this->filter['company']= strtoupper($p_company);
+        }
+        return $this;
+    }
+    function filter_search($p_search="") {
+        unset($this->filter['search']);
+        if ( ! empty($p_search) ){
+            $this->filter['search']=$p_search;
+        }
+    }
+
+    /**
+     * @return array
+     */
+    public function getFilter(): array
+    {
+        return $this->filter;
+    }
+
+    /*!
+     * @brief display a summary of the contact card,
      *
-     * @param  p_search : filter on card name
-     * @param  p_action : nothing
-     * @param  p_sql : extra SQL command
-     * @param  p_nothing (filter)
+     * @param  string p_search : filter on card name, if empty , 
contact->filter will be used
+     * @param  string  p_action :  not used
+     * @param  string p_sql : extra SQL command not used
+     * @param  string  p_nothing (filter) not used
      *
      * @returns string to display
      */
     function Summary($p_search="",$p_action="",$p_sql="",$p_nothing=false)
     {
-        $p_search=sql_string($p_search);
-        $extra_sql="";
-        if ( $this->company != "")
-        {
-            $extra_sql="and f_id in (select f_id from fiche_detail
-                       where 
ad_value='".sql_string(trim(strtoupper($this->company)))."' and 
ad_id=".ATTR_DEF_COMPANY.") ";
+        $http=new HttpInput();
+        if ( !empty ($p_search) ) { $this->filter_search($p_search);}
+
+        $sql=$this->build_sql($this->filter);
+        if (DEBUGNOALYSS > 1) {
+            print_r("Contact::summary ($sql)");
         }
-        $url=urlencode($_SERVER['REQUEST_URI']);
-        $script=$_SERVER['PHP_SELF'];
         // Creation of the nav bar
         // Get the max numberRow
-        
$all_contact=$this->count_by_modele($this->fiche_def_ref,$p_search,$extra_sql.$p_sql);
+        $all_contact=$this->cn->get_value("select count(*) from ($sql) as m");
+           if ( $all_contact == 0 ) return "";
+
         // Get offset and page variable
-        $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
-        $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
+        $offset=$http->request('offset','number',0);
+        $page=$http->request('page','number',1);
+
         
$bar=navigation_bar($offset,$all_contact,$_SESSION[SESSION_KEY.'g_pagesize'],$page);
-        // set a filter ?
-        $search="";
-        if ( noalyss_trim($p_search) != "" )
-        {
-            $search=" and f_id in
-                    (select f_id from fiche_Detail
-                    where
-                    ad_id=1 and ad_value ilike '%$p_search%') ";
-        }
+
+
         // Get The result Array
-        
$step_contact=$this->get_by_category($offset,$search.$extra_sql.$p_sql);
-
-       if ( $all_contact == 0 ) return "";
-        $r=$bar;
-        $r.='<table id="contact_tb" class="sortable">
-            <TR>
-            <th>Quick Code</th>
-            <th>Nom</th>
-            <th>Prénom</th>
-                       <th>Société</th>
-            <th>Téléphone</th>
-            <th>email</th>
-            <th>Fax</th>
-            </TR>';
-        $base=$_SERVER['PHP_SELF'];
-        // Compute the url
-        $url="";
-        $and="?";
-        $get=$_GET;
-        if ( isset ($get) )
-        {
-            foreach ($get as $name=>$value )
-            {
-                // we clean the parameter offset, step, page and size
-                if (  ! in_array($name,array('f_id','detail')))
-                {
-                    $url.=$and.$name."=".$value;
-                    $and="&";
-                }// if
-            }//foreach
-        }// if
-        $back_url=urlencode($_SERVER['REQUEST_URI']);
-        if ( sizeof ($step_contact ) == 0 )
-            return $r;
-        $idx=0;
-        foreach ($step_contact as $contact )
-        {
-            $l_company=new Fiche($this->cn);
-            
$l_company->get_by_qcode($contact->strAttribut(ATTR_DEF_COMPANY),false);
-            $l_company_name=$l_company->strAttribut(ATTR_DEF_NAME,0);
-            
-            // add popup for detail if the company does exist
-            if ( $l_company_name !="")
-            {
-                $l_company_name=HtmlInput::card_detail($contact->strAttribut
-                        
(ATTR_DEF_COMPANY),$l_company_name,'style="text-decoration:underline;"');
-            }
-            $tr=($idx%2==0)?' <tr class="odd">':'<tr class="even">';
-            $idx++;
-            $r.=$tr;
-            $qcode=$contact->strAttribut(ATTR_DEF_QUICKCODE);
-            $r.='<TD>'.HtmlInput::card_detail($qcode)."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_NAME,0)."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_FIRST_NAME,0)."</TD>";
-            $r.="<TD>".$l_company_name."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_TEL,0)."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_EMAIL,0)."</TD>".
-                "<TD> ".$contact->strAttribut(ATTR_DEF_FAX,0)."</TD>";
-
-            $r.="</TR>";
+        $step_contact=$this->fetch($sql);
+
+
+        $contact=$this;
+        require NOALYSS_TEMPLATE.'/contact-summary.php';
 
-        }
-        $r.="</TABLE>";
-        $r.=$bar;
-        return $r;
     }
 
+    /**
+     * @brief Fetch all rows from view, ordered by  by contact_name, with 
offset and limit
+     * @see Contact::build_sql()
+     * @param $ps_string
+     * @return array
+     */
+   private function fetch($ps_sql) {
+        $http=new HttpInput();
+        // Get offset and page variable
+        $offset=$http->request('offset','number',0);
+        $nb_pagesize=$_SESSION[SESSION_KEY.'g_pagesize'];
+        $limit = '';
+        $ps_sql.=' order by contact_name ';
+        if ( $nb_pagesize <0 ) {$limit='';} else {
+            $limit=sprintf(' limit %s offset %s',$nb_pagesize,$offset);
+        }
+        $ps_sql .=  $limit ;
+        if (DEBUGNOALYSS > 1) {
+            print_r("Contact::fetch ($ps_sql)");
+        }
+        return $this->cn->get_array($ps_sql);
+    }
 }
diff --git a/include/class/follow_up.class.php 
b/include/class/follow_up.class.php
index cdde6d324..ef8ee514f 100644
--- a/include/class/follow_up.class.php
+++ b/include/class/follow_up.class.php
@@ -1301,7 +1301,7 @@ class Follow_Up
                 if ($fiche->id==0)
                     $str=' and false ';
                 else
-                    $str=" and (f_id_dest= ".$fiche->id." or ag_id in (select 
ag_id from action_person as ap where ap.f_id=".$fiche->id.")  )";
+                    $str=" and (f_id_dest= ".$fiche->id." or ag_id in (select 
ag_id from action_person as ap where ap.f_id=".$fiche->id.") or 
ag_contact=".$fiche->id."  )";
             }
         }
         if (isset($p_array['tdoc'])&&$p_array['tdoc'] !=-1)
@@ -1342,7 +1342,7 @@ class Follow_Up
         }
         else
         {
-            $action_query .=" and 
(ag_owner='".$_SESSION[SESSION_KEY.'g_user']."' or 
".self::sql_security_filter($cn, "R")." or ag_dest=-1 )";
+            $action_query .=" and 
(ag_owner='".$_SESSION[SESSION_KEY.'g_user']."' or 
".self::sql_security_filter($cn, "R")." or ag_dest=-1  )";
         }
 
 
@@ -1364,7 +1364,7 @@ class Follow_Up
             $action_query .= Follow_Up::filter_by_tag($cn, $p_array);
         }
         if ( DEBUGNOALYSS > 1) {
-            print "QUERY = [ $action_query.$str]";
+            print __FILE__.__LINE__."QUERY = [ $action_query.$str]";
         }
         return $action_query.$str;
     }
diff --git a/include/constant.php b/include/constant.php
index 992e8913e..849ae0872 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -115,7 +115,7 @@ if (!defined("NOALYSS_PACKAGE_REPOSITORY")) {
 if (!defined("SYSINFO_DISPLAY")) {
     define("SYSINFO_DISPLAY", TRUE);
 }
-define("DBVERSION", 177);
+define("DBVERSION", 178);
 define("MONO_DATABASE", 25);
 define("DBVERSIONREPO", 20);
 define('NOTFOUND', '--not found--');
diff --git a/include/contact.inc.php b/include/contact.inc.php
index 6fb05e8e6..4b1e96b56 100644
--- a/include/contact.inc.php
+++ b/include/contact.inc.php
@@ -20,8 +20,11 @@
 /**\brief include from client.inc.php and concerned only the contact card and
  * the contact category
  */
+
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 
+global $g_user,$cn;
+
 $http=new HttpInput();
 
 $low_action = $http->request('sb','string','list');
@@ -98,26 +101,22 @@ if ($low_action == "list")
              <p class="notice"><?=_("Si vous modifiez un contact, il faut 
recharger la page pour voir les changements")?></p>
         </div>
        <?php
-       $client = new contact($cn);
+       $contact = new contact($cn);
        $search =$http->get("query","string","");
        $sql = "";
        if (isset($_GET['cat']))
        {
            $cat=$http->get("cat","number");
-            if ($cat!= -1 )     $sql = sprintf(" and fd_id = %s", $cat);
+        $contact->filter_category($cat);
        }
        if (isset($_GET['sel_company']))
        {
             $sel_company=$http->get("sel_company");
-           if ($sel_company != '' && $sel_company != "-1")
-            {
-
-                $client->company=$sel_company;
-            }
+            $contact->filter_company($sel_company);
        }
 
        echo '<div class="content">';
-       echo $client->Summary($search,"contact",$sql);
+       echo $contact->Summary($search,"contact",$sql);
 
 
        echo '<br>';
@@ -128,7 +127,7 @@ if ($low_action == "list")
        $f_add_button->label = _('Créer une nouvelle fiche');
        $f_add_button->set_attribute('win_refresh', 'yes');
        $f_add_button->set_attribute('type_cat', FICHE_TYPE_CONTACT);
-       $f_add_button->javascript = " select_card_type(this);";
+       $f_add_button->javascript = "select_card_type(this);";
        echo $f_add_button->input();
 
     $f_cat_button=new IButton('add_cat');
diff --git a/include/database/v_contact_sql.class.php 
b/include/database/v_contact_sql.class.php
new file mode 100644
index 000000000..36e93a7e5
--- /dev/null
+++ b/include/database/v_contact_sql.class.php
@@ -0,0 +1,88 @@
+<?php
+/*
+ * Copyright (C) 2017 Dany De Bontridder <dany@alchimerys.be>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+* class_user_filter_sql.php
+*
+* @file
+* @brief abstract of the view public.v_contact
+*/
+
+/**
+* @class User_filter_SQL
+* @brief ORM abstract of the view public.v_contact_sql
+*/
+
+class V_Contact_SQL extends Data_SQL
+{
+    function __construct($p_cn, $p_id = -1)
+    {
+        $this->table="public.v_contact";
+        $this->primary_key="f_id";
+        
$a_name=explode(",","f_id,contact_fname,contact_name,contact_qcode,contact_company,contact_mobile,contact_phone,contact_email,contact_fax,card_category");
+        $this->type=[];
+        foreach ($a_name as $key) {
+            $this->type[trim($key)]="text";
+            $this->name[trim($key)]=$key;
+        }
+        $this->type['f_id']="number";
+        $this->type['card_category']="number";
+
+        parent::__construct($p_cn, $p_id);
+    }
+
+
+    function insert()
+    {
+      throw new Exception("not implemented");
+    }
+
+    function delete()
+    {
+        throw new Exception("not implemented");
+    }
+
+    function update()
+    {
+        throw new Exception("not implemented");
+    }
+
+    function load()
+    {
+       $array=$this->cn->get_row("select * from ".$this->table." where 
f_id=$1",array($this->f_id));
+       if (empty ($array) ) { $this->f_id=-1;return false;}
+        $this->to_row($array);
+       return true;
+    }
+
+    function seek($cond = '', $p_array = null)
+    {
+        throw new Exception("not implemented");
+    }
+
+    function count($p_where = "", $p_array = null)
+    {
+        throw new Exception("not implemented");
+    }
+
+    function exist()
+    {
+        throw new Exception("not implemented");
+    }
+}
\ No newline at end of file
diff --git a/include/lib/data_sql.class.php b/include/lib/data_sql.class.php
index 61b685cc6..1629148fa 100644
--- a/include/lib/data_sql.class.php
+++ b/include/lib/data_sql.class.php
@@ -241,6 +241,16 @@ abstract class Data_SQL
         return $array;
     }
 
+    /**
+     * @brief turns a row fetched from the DB into a SQL object in updating 
all his attribute
+     * @param $p_array
+     * @return void
+     */
+    public function to_row($p_array) {
+        foreach ($this->name as $name) {
+            $this->$name=$p_array[$name];
+        }
+    }
     /**
      * @brief retrieve array of object thanks a condition
      * @param $cond condition (where clause) (optional by default all the rows 
are fetched)
diff --git a/include/sql/patch/upgrade177.sql b/include/sql/patch/upgrade177.sql
new file mode 100644
index 000000000..7c77c5a9c
--- /dev/null
+++ b/include/sql/patch/upgrade177.sql
@@ -0,0 +1,25 @@
+begin;
+
+
+create or replace view v_contact as
+with contact_data as (select f.f_id , f.fd_id from fiche f join fiche_def fd 
on (f.fd_id=fd.fd_id) where fd.frd_id=16)
+select f_id,
+       (select ad_value from fiche_detail where ad_id=32 and f_id=cd.f_id) as 
contact_fname,
+       (select ad_value from fiche_detail where ad_id=1 and f_id=cd.f_id) as 
contact_name,
+       (select ad_value from fiche_detail where ad_id=23 and f_id=cd.f_id) as 
contact_qcode,
+       (select ad_value from fiche_detail where ad_id=25 and f_id=cd.f_id) as 
contact_company,
+       (select ad_value from fiche_detail where ad_id=27 and f_id=cd.f_id) as 
contact_mobile,
+       (select ad_value from fiche_detail where ad_id=17 and f_id=cd.f_id) as 
contact_phone,
+       (select ad_value from fiche_detail where ad_id=18 and f_id=cd.f_id) as 
contact_email,
+       (select ad_value from fiche_detail where ad_id=26 and f_id=cd.f_id) as 
contact_fax,
+       cd.fd_id as card_category
+from contact_data cd   ;
+
+insert into attr_min values (16,32);
+
+insert into jnt_fic_attr (fd_id,jnt_order,ad_id) select fd_id,10,32 from 
fiche_def where frd_id=16 on conflict(fd_id,ad_id) do nothing;
+update attr_def set ad_text='Tél. Portable' where ad_id=27;
+
+
+insert into version (val,v_description) values (178,'Correct contact');
+commit;
\ No newline at end of file
diff --git a/include/template/contact-summary.php 
b/include/template/contact-summary.php
new file mode 100644
index 000000000..d13a34695
--- /dev/null
+++ b/include/template/contact-summary.php
@@ -0,0 +1,96 @@
+<?php
+/**
+ * @brief display table of contact, called from Contact::summary
+ *
+ */
+// From calling script : $step_contact,$bar,$offset,$page
+$cn=Dossier::connect();
+$http=new HttpInput();
+$from=$http->request("ac","string","");
+?>
+<?php echo $bar;?>
+<table id="contact_tb" class="sortable">
+    <TR>
+        <th><?=_('Code')?></th>
+        <th><?=_('Nom')?></th>
+        <th><?=_('Prénom')?></th>
+        <th><?=_('Société')?></th>
+        <th><?=_('Mobile')?></th>
+        <th><?=_('email')?></th>
+        <th><?=_('Téléphone')?></th>
+        <th><?=_('Fax')?></th>
+    </TR>
+    <?php
+    $idx=0;
+    $dossier_id=Dossier::id();
+    $ac=$http->request('ac');
+    foreach ($step_contact as $contact):
+        $even_odd=($idx%2==0)?'even':'odd';
+        $idx++;
+        
$url=NOALYSS_URL."/do.php?".http_build_query(["gDossier"=>$dossier_id,"ac"=>$ac,"sb"=>"detail","f_id"=>$contact['f_id']]);
+    ?>
+    <tr class="<?=$even_odd?>">
+        <td>
+            <?php if (  strpos($from,'CONTACT') !== false ):?>
+            <a href="<?=$url?>">
+            <?=h($contact['contact_qcode'])?>
+            </a>
+            <?php else :?>
+            <?php
+            $fiche=new Fiche($cn,$contact['f_id']);
+            echo \HtmlInput::card_detail($contact['contact_qcode']);
+            ?>
+            <?php endif;?>
+        </td>
+
+        <td>
+            <?=$contact['contact_name']?>
+        </td>
+        <td>
+            <?=$contact['contact_fname']?>
+        </td>
+        <td>
+            <?php
+
+            /* detail for the company */
+            if ( !empty ($contact['contact_company']) ) {
+                $l_company=new Fiche($cn);
+                
$l_company->get_by_qcode(trim($contact['contact_company']),false);
+                $l_company_name=$l_company->strAttribut(ATTR_DEF_NAME,0);
+
+                // add popup for detail if the company does exist
+                if ( $l_company_name !="")
+                {
+                    echo 
HtmlInput::card_detail($contact['contact_company'],$l_company_name,'style="text-decoration:underline;"');
+                }
+            }
+
+            ?>
+        </td>
+        <td>
+            <?=$contact['contact_mobile']?>
+        </td>
+        <td>
+            <?php
+            $result=mailTo($contact['contact_email']);
+            if ($result) {
+                echo $result;
+            } else {
+                echo $contact['contact_email'];
+                echo Icon_Action::warnbulle(83);
+            }
+            ?>
+        </td>
+        <td>
+            <?php if (!empty($contact['contact_phone'])):?>
+                <a 
href="tel:<?=$contact['contact_phone']?>"><?=$contact['contact_phone']?></a>
+            <?php endif;?>
+        </td>
+        <td>
+            <?=$contact['contact_phone']?>
+        </td>
+    </tr>
+    <?php endforeach;?>
+</table>
+
+<?php echo $bar;?>
\ No newline at end of file
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 34d3b0373..e69de29bb 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -1,171 +0,0 @@
--- auto-generated definition
-create table acc_other_tax
-(
-    ac_id             serial        constraint acc_other_tax_pk            
primary key,
-    ac_label       text         not null,
-    ac_rate numeric (5,2) not null,
-    ajrn_def_id    integer[],
-    ac_accounting account_type not null
-);
-comment on table acc_other_tax is 'Additional tax for Sale or Purchase ';
-comment on column acc_other_tax.ac_label is 'Label of the tax';
-comment on column acc_other_tax.ac_rate is 'rate of the tax in percent';
-comment on column acc_other_tax.ajrn_def_id is 'array of to FK jrn_def 
(jrn_def_id)';
-comment on column acc_other_tax.ac_accounting is 'FK tmp_pcmn (pcm_val)';
-
-
-ALTER TABLE public.jrn drop CONSTRAINT jrn_pkey ;
-ALTER TABLE public.jrn ADD CONSTRAINT jrn_pkey PRIMARY KEY (jr_id);
-
--- public.jrn_tax definition
-
--- Drop table
-
--- DROP TABLE public.jrn_tax;
-
-CREATE TABLE public.jrn_tax (
-                                jt_id int4 NOT NULL GENERATED ALWAYS AS 
IDENTITY,
-                                j_id int8 NOT NULL, -- fk jrnx
-                                pcm_val public."account_type" NOT NULL, -- FK 
tmp_pcmn
-                                ac_id int4 NOT NULL, -- FK to acc_other_tax
-                                CONSTRAINT jrn_tax_pk PRIMARY KEY (jt_id)
-);
-
--- Column comments
-
-COMMENT ON COLUMN public.jrn_tax.j_id IS 'fk jrnx';
-COMMENT ON COLUMN public.jrn_tax.pcm_val IS 'FK tmp_pcmn';
-COMMENT ON COLUMN public.jrn_tax.ac_id IS 'FK to acc_other_tax';
-
-
--- public.jrn_tax foreign keys
-
-ALTER TABLE public.jrn_tax ADD CONSTRAINT jrn_tax_acc_other_tax_fk FOREIGN KEY 
(ac_id) REFERENCES public.acc_other_tax(ac_id);
-ALTER TABLE public.jrn_tax ADD CONSTRAINT jrn_tax_fk FOREIGN KEY (j_id) 
REFERENCES public.jrnx(j_id);
-
-drop view if exists v_detail_sale;
-create or replace view v_detail_sale
-            (jr_id, jr_date, jr_date_paid, jr_ech, jr_tech_per, jr_comment, 
jr_pj_number, jr_internal, jr_def_id,
-             j_poste, j_text, j_qcode, jr_rapt, item_card, item_name, 
qs_client, tiers_name, quick_code, tva_label,
-             tva_comment, tva_both_side, vat_sided, vat_code, vat, price, 
quantity, price_per_unit, htva, tot_vat,
-             tot_tva_np,other_tax_amount, oc_amount, oc_vat_amount, 
cr_code_iso)
-as
-WITH m AS (
-    SELECT sum(quant_sold_1.qs_price)     AS htva,
-           sum(quant_sold_1.qs_vat)       AS tot_vat,
-           sum(quant_sold_1.qs_vat_sided) AS tot_tva_np,
-           jrn_1.jr_id
-    FROM quant_sold quant_sold_1
-             JOIN jrnx jrnx_1 USING (j_id)
-             JOIN jrn jrn_1 ON jrnx_1.j_grpt = jrn_1.jr_grpt_id
-    GROUP BY jrn_1.jr_id
-),other_tax as (
-    select j_grpt , sum(case when j_debit is true then 0-j_montant else 
j_montant end) other_tax_amount from jrnx join jrn_tax using (j_id) group by 
j_grpt  )
-SELECT jrn.jr_id,
-       jrn.jr_date,
-       jrn.jr_date_paid,
-       jrn.jr_ech,
-       jrn.jr_tech_per,
-       jrn.jr_comment,
-       jrn.jr_pj_number,
-       jrn.jr_internal,
-       jrn.jr_def_id,
-       jrnx.j_poste,
-       jrnx.j_text,
-       jrnx.j_qcode,
-       jrn.jr_rapt,
-       quant_sold.qs_fiche                          AS item_card,
-       a.name                                       AS item_name,
-       quant_sold.qs_client,
-       b.vw_name                                    AS tiers_name,
-       b.quick_code,
-       tva_rate.tva_label,
-       tva_rate.tva_comment,
-       tva_rate.tva_both_side,
-       quant_sold.qs_vat_sided                      AS vat_sided,
-       quant_sold.qs_vat_code                       AS vat_code,
-       quant_sold.qs_vat                            AS vat,
-       quant_sold.qs_price                          AS price,
-       quant_sold.qs_quantite                       AS quantity,
-       quant_sold.qs_price / quant_sold.qs_quantite AS price_per_unit,
-       m.htva,
-       m.tot_vat,
-       m.tot_tva_np,
-       ot.other_tax_amount,
-       oc.oc_amount,
-       oc.oc_vat_amount,
-       (SELECT currency.cr_code_iso
-        FROM currency
-        WHERE jrn.currency_id = currency.id)        AS cr_code_iso
-FROM jrn
-         JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt
-         JOIN quant_sold USING (j_id)
-         JOIN vw_fiche_name a ON quant_sold.qs_fiche = a.f_id
-         JOIN vw_fiche_attr b ON quant_sold.qs_client = b.f_id
-         LEFT JOIN tva_rate ON quant_sold.qs_vat_code = tva_rate.tva_id
-         JOIN m ON m.jr_id = jrn.jr_id
-         LEFT JOIN operation_currency oc ON oc.j_id = jrnx.j_id
-         left join other_tax ot on ot.j_grpt=jrn.jr_grpt_id;
-
-drop view if exists public.v_detail_purchase;
-
-create VIEW public.v_detail_purchase
-AS WITH m AS (
-    SELECT sum(quant_purchase_1.qp_price) AS htva,
-           sum(quant_purchase_1.qp_vat) AS tot_vat,
-           sum(quant_purchase_1.qp_vat_sided) AS tot_tva_np,
-           jrn_1.jr_id
-    FROM quant_purchase quant_purchase_1
-             JOIN jrnx jrnx_1 USING (j_id)
-             JOIN jrn jrn_1 ON jrnx_1.j_grpt = jrn_1.jr_grpt_id
-    GROUP BY jrn_1.jr_id
-),other_tax as (
-    select j_grpt , sum(case when j_debit is false then 0-j_montant else 
j_montant end) other_tax_amount from jrnx join jrn_tax using (j_id) group by 
j_grpt  )
-   SELECT jrn.jr_id,
-          jrn.jr_date,
-          jrn.jr_date_paid,
-          jrn.jr_ech,
-          jrn.jr_tech_per,
-          jrn.jr_comment,
-          jrn.jr_pj_number,
-          jrn.jr_internal,
-          jrn.jr_def_id,
-          jrnx.j_poste,
-          jrnx.j_text,
-          jrnx.j_qcode,
-          jrn.jr_rapt,
-          quant_purchase.qp_fiche AS item_card,
-          a.name AS item_name,
-          quant_purchase.qp_supplier,
-          b.vw_name AS tiers_name,
-          b.quick_code,
-          tva_rate.tva_label,
-          tva_rate.tva_comment,
-          tva_rate.tva_both_side,
-          quant_purchase.qp_vat_sided AS vat_sided,
-          quant_purchase.qp_vat_code AS vat_code,
-          quant_purchase.qp_vat AS vat,
-          quant_purchase.qp_price AS price,
-          quant_purchase.qp_quantite AS quantity,
-          quant_purchase.qp_price / quant_purchase.qp_quantite AS 
price_per_unit,
-          quant_purchase.qp_nd_amount AS non_ded_amount,
-          quant_purchase.qp_nd_tva AS non_ded_tva,
-          quant_purchase.qp_nd_tva_recup AS non_ded_tva_recup,
-          m.htva,
-          m.tot_vat,
-          m.tot_tva_np,
-          ot.other_tax_amount,
-          oc.oc_amount,
-          oc.oc_vat_amount,
-          ( SELECT currency.cr_code_iso
-            FROM currency
-            WHERE jrn.currency_id = currency.id) AS cr_code_iso
-   FROM jrn
-            JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt
-            JOIN quant_purchase USING (j_id)
-            JOIN vw_fiche_name a ON quant_purchase.qp_fiche = a.f_id
-            JOIN vw_fiche_attr b ON quant_purchase.qp_supplier = b.f_id
-            LEFT JOIN tva_rate ON quant_purchase.qp_vat_code = tva_rate.tva_id
-            JOIN m ON m.jr_id = jrn.jr_id
-            LEFT JOIN operation_currency oc ON oc.j_id = jrnx.j_id
-            left join other_tax ot on ot.j_grpt=jrn.jr_grpt_id;
\ No newline at end of file
diff --git a/unit-test/include/class/contactTest.php 
b/unit-test/include/class/contactTest.php
index e3e6d4517..f6b792687 100644
--- a/unit-test/include/class/contactTest.php
+++ b/unit-test/include/class/contactTest.php
@@ -28,12 +28,11 @@
  */
 use PHPUnit\Framework\TestCase;
 
+require DIRTEST.'/global.php';
 /**
  * @backupGlobals enabled
  * @coversDefaultClass \Contact
  */
-require DIRTEST.'/global.php';
-
 class ContactTest extends TestCase
 {
 
@@ -41,6 +40,7 @@ class ContactTest extends TestCase
      * @var Fiche
      */
     protected $object;
+    protected $connection;
 
     /**
      * Sets up the fixture, for example, opens a network connection.
@@ -48,10 +48,11 @@ class ContactTest extends TestCase
      */
     protected function setUp():void
     {
-        include 'global.php';
+
         $this->object = new stdClass();
         $this->object->fiche_def=0;
         $this->object->card_to_clean=array();
+        $this->connection=Dossier::connect();
     }
 
     /**
@@ -60,8 +61,9 @@ class ContactTest extends TestCase
      */
     protected function tearDown():void
     {
-        include 'global.php';
-        global $g_connection;
+        if ( ! is_object($this->object->fiche_def)) return;
+        include_once DIRTEST.'/global.php';
+        $g_connection=Dossier::connect();
         $sql=new ArrayObject();
         $sql->append("delete from fiche_detail where f_id in (select f_id from 
fiche where fd_id = $1 )");
         $sql->append("delete from fiche where f_id not in (select f_id from 
fiche_detail where $1=$1)");
@@ -101,9 +103,9 @@ class ContactTest extends TestCase
      */
     public function createContact()
     {
-        include_once 'global.php';
+        include_once DIRTEST.'/global.php';
 
-        global $g_connection;
+        $g_connection=Dossier::connect();
         // create a category of card, type Charges
         $fiche_def=new Fiche_Def($g_connection);
         $aParam=["nom_mod"=>"Test.Contact", 
@@ -127,7 +129,8 @@ class ContactTest extends TestCase
      */
     public function createContactCard()
     {
-        global $g_connection;
+        include_once DIRTEST.'/global.php';
+
         if ( $this->object->fiche_def == 0) {
             $this->createContact();
         }
@@ -139,7 +142,7 @@ class ContactTest extends TestCase
         $aName[]=['name'=>'Daniel','company'=>'FOURNI'];
         $aName[]=['name'=>'Geert','company'=>'FOURNI'];
         foreach ($aName as $param  ) {
-            $fiche=new Fiche($g_connection);
+            $fiche=new Fiche($this->connection);
             $fiche->fiche_def=$this->object->fiche_def->id;
             $fiche->load();
             $fiche->setAttribut(ATTR_DEF_NAME, $param['name']);
@@ -157,6 +160,7 @@ class ContactTest extends TestCase
      */
     public function testSummary()
     {
+        include_once DIRTEST.'/global.php';
         global $g_connection;
         if ( $this->object->fiche_def == 0) {
             $this->createContactCard();
@@ -164,14 +168,110 @@ class ContactTest extends TestCase
         $contact=new Contact($g_connection);
         $_SERVER['REQUEST_URI']="?";
         $_SERVER['PHP_SELF']=__FILE__;
-        $r=$contact->summary();
-        $this->assertEquals(count($this->object->card_to_clean)*2 , 
substr_count($r,'fill_ipopcard')," 1. Missing card");
-        $contact->company=' fourni ';
-        $r=$contact->summary();
-        $this->assertEquals(6, substr_count($r,'fill_ipopcard') , 'not found 
all the contacts from FOURNI');
-        $r=$contact->summary('william');
-        $this->assertEquals(2, substr_count($r,'fill_ipopcard') , 'Search does 
not filter');
+        put_global(array(
+                    ["key"=>"offset","value"=>0],
+                    ["key"=>"ac","value"=>"CONTACT"],
+                    ["key"=>"page","value"=>1]));
+        ob_start();
+        $contact->summary();
+        $r=ob_get_contents();
+        ob_end_clean();
+        $path=__DIR__."/file/";
+        $filename="contact-summary-1.html";
+        \Noalyss\Facility::save_file($path,$filename,$r);
+        print "File saved into $path/$filename";
+        $this->assertEquals(4983, filesize ($path."/".$filename)," File not 
valide (1)");
+        $this->assertEquals(5 , preg_match_all('/<tr class="/',$r)," 1. 
Missing card");
+        $contact->filter_company(' fourni ');
+        ob_start();
+        $contact->summary();
+        $r=ob_get_contents();
+        ob_end_clean();
+        $filename="contact-summary-2.html";
+        \Noalyss\Facility::save_file($path,$filename,$r);
+
+        print "File saved into $path/$filename";
+        $this->assertEquals(3457,filesize ($path."/".$filename)," File not 
valide (2)");
+        $this->assertEquals(3 , preg_match_all('/<tr class="/',$r), 'not found 
all the contacts from FOURNI');
+
+
+        ob_start();
+        $contact->summary('william');
+        $r=ob_get_contents();
+        ob_end_clean();
+        $filename="contact-summary-3.html";
+        \Noalyss\Facility::save_file($path,$filename,$r);
+        print "File saved into $path/$filename";
+        $this->assertEquals(2018,filesize ($path."/".$filename)," File not 
valide (3)");
+        $this->assertEquals(1, preg_match_all('/<tr class="/',$r), 'Search 
does not filter');
         
     }
 
+    /**
+     * @testdox test the filters
+     * @return void
+     */
+    public function testFilter()
+    {
+        $contact=new Contact($this->connection);
+        $this->assertEquals(array(),$contact->getFilter(),' Filter not empty');
+        $contact->filter_search("search_sql");
+        
$this->assertEquals(['search'=>'search_sql'],$contact->getFilter(),'Search not 
set');
+
+        $contact->filter_search("other_sql");
+        
$this->assertEquals(['search'=>'other_sql'],$contact->getFilter(),'Search not 
replaced');
+
+        $contact->filter_company("company_sql");
+        
$this->assertEquals(['search'=>'other_sql','company'=>'COMPANY_SQL'],$contact->getFilter(),'company
 not set');
+
+        $contact->filter_category(1);
+        
$this->assertEquals(['search'=>'other_sql','company'=>'COMPANY_SQL','category'=>1],
+            $contact->getFilter(),'category not set');
+
+        $contact->filter_category(null);
+        
$this->assertEquals(['search'=>'other_sql','company'=>'COMPANY_SQL'],$contact->getFilter(),'category
 not removed');
+
+    }
+
+    /**
+     * @depends testFilter
+     * @return void
+     */
+    function testBuildSQL()
+    {
+        $contact=new Contact($this->connection);
+        $contact->filter_category(1);
+        $contact->filter_search("search_sql");
+        $expected=strtoupper(preg_replace("/\s+/",'',"SELECT 
f_id,contact_fname, 
+               contact_name, 
+               contact_qcode, 
+               contact_company, 
+               contact_mobile, 
+               contact_phone, 
+               contact_email, 
+               contact_fax
+        FROM public.v_contact 
+        where  f_id in (select distinct f_id from fiche_detail where ad_value 
ilike '%search_sql%') and fd_id=1"));
+        
$this->assertEquals($expected,strtoupper(preg_replace("/\s+/",'',$contact->build_sql([]))),'
 SQL Incorrect');
+
+    }
+
+    /**
+     * @testdox Test SQL V_Contact_SQL
+     * @return void
+     */
+    function testObjectSQL()
+    {
+        if ( $this->object->fiche_def == 0) {
+            $this->createContactCard();
+        }
+        // take a card
+        $f_id=$this->object->card_to_clean[0];
+        $contact_sql=new V_Contact_SQL($this->connection,$f_id);
+        $this->assertTrue($contact_sql->load()," Cannot load existing card");
+        $this->assertTrue($contact_sql->contact_name=='Chantal','Data not 
updated');
+        $this->assertTrue($contact_sql->getp("contact_name")=='Chantal','Data 
not updated');
+    }
+
+
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]