diff --git a/html/js/card.js b/html/js/card.js index 1eeedfda6..ef115ce38 100644 --- a/html/js/card.js +++ b/html/js/card.js @@ -79,6 +79,11 @@ function search_card(obj) var price=obj.price; var tvaid=obj.tvaid; var jrn=obj.jrn; + var amount_from_type=0; + if ( obj.amount_from_type) { + amount_from_type=obj.amount_from_type; + + } if ( jrn==undefined) { if ( g('p_jrn')) { @@ -98,7 +103,8 @@ function search_card(obj) 'inp':inp,'label':label,'price':price,'tvaid':tvaid, 'ctl':'search_card','op2':'fs','jrn':jrn, 'typecard':typecard,'query':string_to_search,'op':'card', - 'accvis':accvis + 'accvis':accvis, + 'amount_from_type':amount_from_type }); if ( $('search_card') ) { removeDiv('search_card'); @@ -318,7 +324,8 @@ function search_get_card(obj) queryString+="&accvis="+$F(accvis); } else { queryString+="&accvis=0"; - } + } + queryString=encodeURI(queryString); $('asearch').innerHTML=loading(); diff --git a/include/ajax/ajax_add_concerned_card.php b/include/ajax/ajax_add_concerned_card.php index 90f3281b4..a30f1cce5 100644 --- a/include/ajax/ajax_add_concerned_card.php +++ b/include/ajax/ajax_add_concerned_card.php @@ -1,4 +1,4 @@ -get_type(); } + // if jrn == -10 , the search is called from the detail operation from an action follow-up + if ( isset($jrn) && $jrn == -10){ + $type=$http->request("amount_from_type","string","VEN"); + } $fiche=new Fiche($cn); /* Build the SQL and show result */ $sql=$fiche->build_sql($sql_array); @@ -496,7 +500,7 @@ case 'fs': $price,$amount); } if ( $type=="VEN" ){ - $amount=(isNumber($a[$i]['vw_buy']) == 1 )?$a[$i]['vw_sell']:0; + $amount=(isNumber($aFound[$i]['vw_buy']) == 1 )?$aFound[$i]['vw_sell']:0; $array[$i]['javascript'].=sprintf("set_value('%s','%s');", $price,$amount); } diff --git a/include/class/action_document_type_mtable.class.php b/include/class/action_document_type_mtable.class.php index b6fb26376..bd41af234 100644 --- a/include/class/action_document_type_mtable.class.php +++ b/include/class/action_document_type_mtable.class.php @@ -80,6 +80,7 @@ class Action_Document_Type_MTable extends Manage_Table_SQL $this->other['contact_multiple']=$http->request("det_contact_mul", "string", 0); $this->other['make_invoice']=$http->request("make_invoice", "string", 0); $this->other['seq']=$http->request("seq", "string", 0); + $this->other['select_option_operation']=$http->request("select_option_operation", "string", null); } /** @@ -172,9 +173,13 @@ class Action_Document_Type_MTable extends Manage_Table_SQL $doc_type->set_number($this->other['seq']); } // Save detail operation - $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable) values ($1,$2,$3) + $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable,do_option) values ($1,$2,$3,$4) on conflict on constraint document_option_un - do update set do_enable=$3", ["detail_operation", $object_sql->dt_id, $this->other['detail_operation']]); + do update set do_enable=$3,do_option=$4", ["detail_operation", + $object_sql->dt_id, + $this->other['detail_operation'], + $this->other['select_option_operation'] + ]); // Save contact_multiple $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable) values ($1,$2,$3) @@ -185,6 +190,8 @@ class Action_Document_Type_MTable extends Manage_Table_SQL $cn->exec_sql("insert into document_option (do_code,document_type_id,do_enable) values ($1,$2,$3) on conflict on constraint document_option_un do update set do_enable=$3 ", ["make_invoice", $object_sql->dt_id, $this->other['make_invoice']]); + + } } diff --git a/include/class/document_option.class.php b/include/class/document_option.class.php index 5d68874bd..cc5553356 100644 --- a/include/class/document_option.class.php +++ b/include/class/document_option.class.php @@ -48,6 +48,20 @@ class Document_Option } return $display_operation; } + /** + * returns option from the operation_detail + * + * @param int $p_document_type Document_Type.dt_id + * @return string + */ + static function option_operation_detail($p_document_type) + { + $cn=Dossier::connect(); + $option_operation = $cn->get_value("select do_option from document_option where document_type_id=$1 " + . " and do_code = $2", + [$p_document_type, 'detail_operation']); + return $option_operation; + } /** * returns true if the operation_detail is enable, otherwise false diff --git a/include/lib/icard.class.php b/include/lib/icard.class.php index d0bfa419a..9fbb74153 100644 --- a/include/lib/icard.class.php +++ b/include/lib/icard.class.php @@ -136,6 +136,7 @@ class ICard extends HtmlInput $this->style=' '; $this->accvis=1; //!< account_visible =1 otherwise 0 $this->limit=12; //!< Max of row show + $this->amount_from_type=''; //!< in the follow up ,when a card is selected you take Prix Vente or Prix Achat } /** @@ -322,7 +323,7 @@ class ICard extends HtmlInput if (!isset($this->id)) $this->id=$this->name; $a=""; - foreach (array('typecard', 'jrn', 'label', 'price', 'tvaid', 'accvis') as + foreach (array('typecard', 'jrn', 'label', 'price', 'tvaid', 'accvis','amount_from_type') as $att) { if (isset($this->$att)) diff --git a/include/template/action_document_type_mtable_input.php b/include/template/action_document_type_mtable_input.php index eee3f0117..eee56aac4 100644 --- a/include/template/action_document_type_mtable_input.php +++ b/include/template/action_document_type_mtable_input.php @@ -70,6 +70,11 @@ $i=new ICheckBox("detail_operation",1); if ( Document_Option::is_enable_operation_detail($table->dt_id)) $i->set_check(1);else $i->set_check(0); echo $i->input(); echo _("Détail opération"); +$select_detail_operation=new ISelect("select_option_operation"); +$select_detail_operation->value=array(["value"=>"VEN","label"=>_("Prix vente")], + ["value"=>"ACH","label"=>_("Prix achat")]); +$select_detail_operation->set_value(Document_Option::option_operation_detail($table->dt_id)); +echo $select_detail_operation->input(); ?>
  • diff --git a/include/template/follow_up_detail_display.php b/include/template/follow_up_detail_display.php index 0ce27e905..a86a2e844 100644 --- a/include/template/follow_up_detail_display.php +++ b/include/template/follow_up_detail_display.php @@ -32,6 +32,11 @@ $text=new IText(); $num=new INum(); $itva=new ITva_Popup(); $readonly=($p_view == "READ")?true:false; +// Check for the Price on ACH or VEN +$cn=Dossier::connect(); +$document_type=$p_follow_up->db->get_value("select ag_type from action_gestion where ag_id = $1",[$p_follow_up->ag_id]); +$option_detail= Document_Option::option_operation_detail($document_type); + // default menu for invoice $menu=new Default_Menu(); ?> @@ -53,7 +58,7 @@ $menu=new Default_Menu(); for ($i=0; $i<$article_count; $i++): /* fid = Icard */ $icard=new ICard(); - $icard->jrn=0; + $icard->jrn=-10; $icard->table=0; $icard->noadd="no"; $icard->extra='all'; @@ -81,6 +86,13 @@ $menu=new Default_Menu(); $icard->set_attribute('ipopup', 'ipopcard'); $icard->set_function('fill_data'); $icard->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ', $icard->name); + // name of the field to update with the name of the card + $icard->set_attribute('label', 'e_march' . $i . '_label'); + // name of the field with the price + $icard->set_attribute('price', 'e_march' . $i . '_price'); + // name of the field with the TVA_ID + $icard->set_attribute('tvaid', 'e_march' . $i . '_tva_id'); + $icard->amount_from_type=$option_detail; $aArticle[$i]['fid']=$icard->search().$icard->input(); diff --git a/sql/upgrade.sql b/sql/upgrade.sql index daa9ad83f..54c62c600 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -1,191 +1,2 @@ - -CREATE OR REPLACE FUNCTION comptaproc.jrn_check_periode() - RETURNS trigger -AS $function$ -declare -bClosed bool; -str_status text; -ljr_tech_per jrn.jr_tech_per%TYPE; -ljr_def_id jrn.jr_def_id%TYPE; -lreturn jrn%ROWTYPE; -begin -if TG_OP='UPDATE' then - ljr_tech_per :=OLD.jr_tech_per ; - NEW.jr_tech_per := comptaproc.find_periode(to_char(NEW.jr_date,'DD.MM.YYYY')); - ljr_def_id :=OLD.jr_def_id; - lreturn :=NEW; - if NEW.jr_date = OLD.jr_date then - return NEW; - end if; - if comptaproc.is_closed(NEW.jr_tech_per,NEW.jr_def_id) = true then - raise exception 'Periode fermee'; - end if; -end if; - -if TG_OP='INSERT' then - NEW.jr_tech_per := comptaproc.find_periode(to_char(NEW.jr_date,'DD.MM.YYYY')); - ljr_tech_per :=NEW.jr_tech_per ; - ljr_def_id :=NEW.jr_def_id; - lreturn :=NEW; -end if; - -if TG_OP='DELETE' then - ljr_tech_per :=OLD.jr_tech_per; - ljr_def_id :=OLD.jr_def_id; - lreturn :=OLD; -end if; - -if comptaproc.is_closed (ljr_tech_per,ljr_def_id) = true then - raise exception 'Periode fermee'; -end if; - -return lreturn; -end; -$function$; -LANGUAGE plpgsql; - --- New right for action : delete -ALTER TABLE public.user_sec_action_profile drop CONSTRAINT user_sec_action_profile_ua_right_check; -ALTER TABLE public.user_sec_action_profile ADD CONSTRAINT user_sec_action_profile_ua_right_check check (ua_right in ('R','W','X','O')); - --- extension CRM : definition des options qu'on peut ajouter --- public.document_option_ref definition - --- Drop table - --- DROP TABLE public.document_option_ref; - -CREATE TABLE public.document_option_ref ( - do_id bigserial NOT NULL, - do_code varchar(20) NOT NULL, -- Code of the option to add - document_type_id int8 NULL, -- FK to document_type - CONSTRAINT document_option_ref_pk PRIMARY KEY (do_id) -); -COMMENT ON TABLE public.document_option_ref IS 'Reference of option of document_type'; - --- Column comments - -COMMENT ON COLUMN public.document_option_ref.do_code IS 'Code of the option to add'; -COMMENT ON COLUMN public.document_option_ref.document_type_id IS 'FK to document_type'; - - --- public.document_option_ref foreign keys - -ALTER TABLE public.document_option_ref ADD CONSTRAINT document_option_ref_fk FOREIGN KEY (document_type_id) REFERENCES document_type(dt_id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- Drop table - -CREATE TABLE public.contact_option_ref ( - cor_id bigserial NOT NULL, - cor_label varchar NOT NULL, -- Label de l'option - cor_type int4 NOT NULL DEFAULT 0, -- 0 text , 1 select ,2 nombre , 3 date - cor_value_json json NULL, -- json object if cor_type is a select - document_option_id int8 NOT NULL, -- FK to document_option - CONSTRAINT contact_option_ref_pk PRIMARY KEY (cor_id), - CONSTRAINT contact_option_ref_fk FOREIGN KEY (document_option_id) REFERENCES document_option(do_id) ON UPDATE CASCADE ON DELETE CASCADE -); -COMMENT ON TABLE public.contact_option_ref IS 'Option for the contact'; - --- Column comments - -COMMENT ON COLUMN public.contact_option_ref.cor_label IS 'Label de l''option'; -COMMENT ON COLUMN public.contact_option_ref.cor_type IS '0 text , 1 select ,2 nombre , 3 date'; -COMMENT ON COLUMN public.contact_option_ref.cor_value_json IS 'json object if cor_type is a select'; -COMMENT ON COLUMN public.contact_option_ref.document_option_id IS 'FK to document_option'; - - - - --- renomme le menu -update menu_ref set me_description = 'Configuration des documents dans le suivi' ,me_file='cfg_action.inc.php' , -me_description_etendue ='Vous permet d''ajouter de nouveaux type de documents pour le suivi (bordereau de livraison, devis..)',me_code='CFGACTION', -me_menu='Document Suivi' -where me_code='CFGCATDOC'; - - -ALTER TABLE public.document_option ADD do_activate int NOT NULL DEFAULT 1; -COMMENT ON COLUMN public.document_option.do_activate IS '1 the option is activated, 0 is inativated'; - -ALTER TABLE public.document_option ADD CONSTRAINT document_option_un UNIQUE (do_code,document_type_id); -ALTER TABLE public.document_option RENAME COLUMN do_activate TO do_enable; - --- ajoute un menu pour les options de contacts -INSERT INTO public.menu_ref (me_code,me_menu,me_file,me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue) VALUES -('CFGCONTACT','Contact','contact_option_ref.inc.php',NULL,'Configure les options pours les contacts multiples',NULL,NULL,'ME',NULL) -; - -INSERT INTO public.profile_menu (me_code,me_code_dep,p_id,p_order,p_type_display,pm_default,pm_id_dep) VALUES -('CFGCONTACT','DIVPARM',1,85,'E',0,56) -; - --- contact option globale pour toutes les actions -ALTER TABLE public.contact_option_ref DROP COLUMN document_option_id; - --- on utilise un varchar pour stocker les possibilités -ALTER TABLE public.contact_option_ref DROP COLUMN cor_value_json; -ALTER TABLE public.contact_option_ref ADD cor_value_select varchar NULL; -COMMENT ON COLUMN public.contact_option_ref.cor_value_select IS 'Select values'; - - -CREATE TABLE public.tag_group ( - tg_id bigserial NOT NULL, - tg_name varchar NOT NULL -); -COMMENT ON TABLE public.tag_group IS 'Group of tags'; - --- Column comments - -COMMENT ON COLUMN public.tag_group.tg_name IS 'Nom du groupe'; -ALTER TABLE public.tag_group ADD CONSTRAINT tag_group_pk PRIMARY KEY (tg_id); - --- public.jnt_tag_group_tag definition - --- Drop table - --- DROP TABLE public.jnt_tag_group_tag; - -CREATE TABLE public.jnt_tag_group_tag ( - tag_group_id int8 NOT NULL, - tag_id int8 NOT NULL, - jt_id serial NOT NULL, - CONSTRAINT jnt_tag_group_tag_pkey PRIMARY KEY (jt_id), - CONSTRAINT jnt_tag_group_tag_un UNIQUE (tag_id, tag_group_id) -); -COMMENT ON TABLE public.jnt_tag_group_tag IS 'Many to Many table betwwen tag and tag group'; - - --- public.jnt_tag_group_tag foreign keys - -ALTER TABLE public.jnt_tag_group_tag ADD CONSTRAINT jnt_tag_group_tag_fk FOREIGN KEY (tag_id) REFERENCES tags(t_id) ON UPDATE CASCADE ON DELETE CASCADE; -ALTER TABLE public.jnt_tag_group_tag ADD CONSTRAINT jnt_tag_group_tag_fk_1 FOREIGN KEY (tag_group_id) REFERENCES tag_group(tg_id) ON UPDATE CASCADE ON DELETE CASCADE; - - -insert into action values (1025,'Ajout d''étiquette','followup','TAGADD'); - --- public.action_person_option definition - --- Drop table - --- DROP TABLE public.action_person_option; - -CREATE TABLE public.action_person_option ( - ap_id bigserial NOT NULL, - ap_value varchar NULL, -- Value of the option - contact_option_ref_id int8 NOT NULL, -- FK to contact_option - action_person_id int8 NOT NULL, -- FK to action_person - CONSTRAINT action_person_option_pk PRIMARY KEY (ap_id) -); -COMMENT ON TABLE public.action_person_option IS 'option for each contact'; - --- Column comments - -COMMENT ON COLUMN public.action_person_option.ap_value IS 'Value of the option'; -COMMENT ON COLUMN public.action_person_option.contact_option_ref_id IS 'FK to contact_option'; -COMMENT ON COLUMN public.action_person_option.action_person_id IS 'FK to action_person'; - - --- public.action_person_option foreign keys - -ALTER TABLE public.action_person_option ADD CONSTRAINT action_person_option_fk FOREIGN KEY (action_person_id) REFERENCES action_person(ap_id) ON UPDATE CASCADE ON DELETE CASCADE; -ALTER TABLE public.action_person_option ADD CONSTRAINT contact_option_ref_fk FOREIGN KEY (contact_option_ref_id) REFERENCES contact_option_ref(cor_id) ON UPDATE CASCADE ON DELETE CASCADE; +ALTER TABLE public.document_option ADD do_option varchar NULL; +COMMENT ON COLUMN public.document_option.do_option IS 'Option for the detail';