<?php
// +-------------------------------------------------+
// | 2002-2011 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: interface_acquisition_ach_cmde_form.class.php,v 1.1.2.3 2026/07/09 12:43:48 dgoron Exp $

if (stristr($_SERVER['REQUEST_URI'], ".class.php")) die("no access");

class interface_acquisition_ach_cmde_form extends interface_acquisition_ach_form {
	
    protected function get_js_script() {
        global $cde_help_jscript, $modif_cde_duplicate_transfer_jscript;
        
        $js_script = "";
        if(!$this->object_id) {		//creation de commmande
            $js_script .= $cde_help_jscript.$modif_cde_duplicate_transfer_jscript;
        } else {		//visualisation ou modification de commmande
            if ($this->statut != STA_ACT_AVA) {	//Commande non modifiable
                $js_script .= $modif_cde_duplicate_transfer_jscript;
            } else {	//Commande modifiable
                $js_script .= $cde_help_jscript.$modif_cde_duplicate_transfer_jscript;
            }
        }
        $js_script .= parent::get_js_script();
        return $js_script;
    }
    
    protected function get_cancel_action() {
        return "./acquisition.php?categ=ach&sub=cmde&action=list&id_bibli=".$this->id_bibli;
    }
	
//     protected function has_act_not_editable() {
//         if ($this->statut != STA_ACT_AVA) {	//Commande non modifiable
//             return true;
//         }
//         return false;
//     }
    
//     protected function has_act_archived() {
//         if (($this->statut & STA_ACT_ARC) == STA_ACT_ARC ){	//Commande archivee
//             return true;
//         }
//         return false;
//     }
    
//     protected function has_act_sold_out() {
//         if (($this->statut & STA_ACT_REC) == STA_ACT_REC) {	//Commande soldee
//             return true;
//         }
//         return false;
//     }
    
    protected function get_display_submit_action() {
        if ($this->statut != STA_ACT_AVA) {	//Commande non modifiable
            if (($this->statut & STA_ACT_ARC) == STA_ACT_ARC ){	//Commande archivee
                return '';
            } else {	//Commande non archivee
                return '';
            }
        }
        $event_function = "
        r=act_verif();
		if (!r) return false;
		act_calc();
		document.forms['act_modif'].setAttribute('action', 'acquisition.php?categ=ach&sub=cmde&action=update');
		document.forms['act_modif'].submit();";
        return $this->get_display_action('save_button', $this->get_action_save_label(), ['function' => $event_function]);
    }
    
    protected function get_action_enr_valid_label() {
        global $msg;
        return $msg["77"];
    }
    
    protected function get_display_enr_valid_action() {
        if ($this->statut != STA_ACT_AVA) {	//Commande non modifiable
            if (($this->statut & STA_ACT_ARC) == STA_ACT_ARC ){	//Commande archivee
                return '';
            }
        } else {
            return '';
        }
        $event_function = "
        document.forms['act_modif'].setAttribute('action', './acquisition.php?categ=ach&sub=cmde&action=update');
		document.forms['act_modif'].submit();";
        return $this->get_display_action('enr_valid_button', $this->get_action_enr_valid_label(), ['function' => $event_function]);
    }
    
    protected function get_action_val_label() {
        global $msg;
        return $msg["acquisition_act_bt_val"];
    }
    
    protected function get_val_action() {
        return $this->get_url_base()."&action=valid";
    }
    
    protected function get_display_val_action() {
        global $msg;
        
        if ($this->statut != STA_ACT_AVA) {	//Commande non modifiable
            if (($this->statut & STA_ACT_ARC) == STA_ACT_ARC ){	//Commande archivee
                return '';
            } else {	//Commande non archivee
                return '';
            }
        }
        $event_function = "
        r=act_verif();
		if (!r) return false;
		act_calc();
		r=confirm('".addslashes($msg['acquisition_cde_val'])."');
		if (!r) return false;
		document.forms['act_modif'].setAttribute('action', 'acquisition.php?categ=ach&sub=cmde&action=valid');
		document.forms['act_modif'].submit();";
        return $this->get_display_action('val_button', $this->get_action_val_label(), ['function' => $event_function]);
    }
    
    protected function get_action_duplicate_label() {
        global $msg;
        return $msg["acquisition_dup"];
    }
    
    protected function get_display_duplicate_action() {
        $event_function = "
        document.forms['act_modif'].setAttribute('action', 'acquisition.php?categ=ach&sub=cmde&action=duplicate');
		document.forms['act_modif'].submit();";
        return $this->get_display_action('duplicate_button', $this->get_action_duplicate_label(), ['function' => $event_function]);
    }
    
    protected function get_action_arc_label() {
        global $msg;
        return $msg['acquisition_act_bt_arc'];
    }
    
    protected function get_arc_action() {
        return $this->get_url_base()."&action=arc";
    }
    
    protected function get_display_arc_action() {
        if ($this->statut != STA_ACT_AVA) {	//Commande non modifiable
            if (($this->statut & STA_ACT_ARC) == STA_ACT_ARC ){	//Commande archivee
                return '';
            } else {	//Commande non archivee
                if (($this->statut & STA_ACT_REC) != STA_ACT_REC) { //Commande non soldee
                    return '';
                }
            }
        }
        $event_function = "
        document.forms['act_modif'].setAttribute('action', './acquisition.php?categ=ach&sub=cmde&action=arc');
		document.forms['act_modif'].submit();";
        return $this->get_display_action('arc_button', $this->get_action_arc_label(), ['function' => $event_function]);
    }
    
    protected function get_imp_action() {
        return "./pdf.php?pdfdoc=cmde&id_bibli=".$this->id_bibli."&id_cde=".$this->object_id;
    }
    
    protected function get_action_rec_label() {
        global $msg;
        return $msg['acquisition_cde_bt_rec'];
    }
    
    protected function get_rec_action() {
        return "./acquisition.php?categ=ach&sub=recept&action=from_cde";
    }
    
    protected function get_display_rec_action() {
        if ($this->statut != STA_ACT_AVA) {	//Commande non modifiable
            if (($this->statut & STA_ACT_ARC) == STA_ACT_ARC ){	//Commande archivee
                return '';
            } else {	//Commande non archivee
                if (($this->statut & STA_ACT_REC) == STA_ACT_REC) {	//Commande soldee
                    return '';
                }
            }
        } else {
            return '';
        }
        $event_function = "
        document.forms['act_modif'].setAttribute('action', '".$this->get_rec_action()."');
		document.forms['act_modif'].submit();";
        return $this->get_display_action('rec_button', $this->get_action_rec_label(), ['function' => $event_function]);
    }
    
    protected function get_action_fac_label() {
        global $msg;
        return $msg['acquisition_cde_bt_fac'];
    }
    
    protected function get_fac_action() {
        return "./acquisition.php?categ=ach&sub=fact&action=from_cde";
    }
    
    protected function get_display_fac_action() {
        if ($this->statut != STA_ACT_AVA) {	//Commande non modifiable
            if (($this->statut & STA_ACT_ARC) == STA_ACT_ARC ){	//Commande archivee
                return '';
            } else {	//Commande non archivee
                if (($this->statut & STA_ACT_FAC) == STA_ACT_FAC) {	//Commande facturee
                    return '';;
                }
            }
        } else {
            return '';
        }
        $event_function = "
        document.forms['act_modif'].setAttribute('action', '".$this->get_fac_action()."');
		document.forms['act_modif'].submit();";
        return $this->get_display_action('fac_button', $this->get_action_fac_label(), ['function' => $event_function]);
    }
    
    protected function get_action_sol_label() {
        global $msg;
        return $msg['acquisition_cde_bt_sol'];
    }
    
    protected function get_sol_action() {
        return "./acquisition.php?categ=ach&sub=cmde&action=sold";
    }
    
    protected function get_display_sol_action() {
        global $msg;
        
        if ($this->statut != STA_ACT_AVA) {	//Commande non modifiable
            if (($this->statut & STA_ACT_ARC) == STA_ACT_ARC ){	//Commande archivee
                return '';
            } else {	//Commande non archivee
                if (($this->statut & STA_ACT_REC) == STA_ACT_REC) {	//Commande soldee
                    return '';
                }
            }
        } else {
            return '';
        }
        $event_function = "
        r = confirm('".addslashes($msg['acquisition_cde_sol'])."');
		if(r) {
			document.forms['act_modif'].setAttribute('action', '".$this->get_sol_action()."');
			document.forms['act_modif'].submit();
        }";
        return $this->get_display_action('sol_button', $this->get_action_sol_label(), ['function' => $event_function]);
    }
    
    protected function get_display_delete_action() {
        global $msg;
        $event_function = "
        if (document.getElementById('id_cde').value == 0) {return false; }
		r = confirm('".addslashes($msg['acquisition_cde_sup'])."');
		if(r){
			document.forms['act_modif'].setAttribute('action', './acquisition.php?categ=ach&sub=cmde&action=delete');
			document.forms['act_modif'].submit();
        }";
        return $this->get_display_action('delete_button', $this->get_action_delete_label(), ['function' => $event_function]);
    }
    
    protected function get_display_actions() {
        global $pmb_type_audit;
        
        if ($this->object_id && ($this->statut != STA_ACT_AVA)) { //modification de commmande et non modifiable
            $display = "
    		<div class='left'>
    			".$this->get_display_cancel_action()."
    			".($this->object_id ? $this->get_display_enr_valid_action() : "")."
    			".($this->object_id && !empty($this->duplicable) ? $this->get_display_duplicate_action() : "")."
    			".($this->object_id ? $this->get_display_rec_action() : "")."
    			".($this->object_id ? $this->get_display_fac_action() : "")."
    			".($this->object_id ? $this->get_display_imp_action() : "")."
                ".($pmb_type_audit && $this->object_id ? $this->get_display_audit_action() : "")."
    		</div>
    		<div class='right'>
    			".($this->object_id ? $this->get_display_sol_action() : "")."
    			".($this->object_id ? $this->get_display_arc_action() : "")."
    		</div>";
        } else {
            $display = "
    		<div class='left'>
    			".$this->get_display_cancel_action()."
    			".$this->get_display_submit_action()."
    			".$this->get_display_val_action()."
    			".($this->object_id && !empty($this->duplicable) ? $this->get_display_duplicate_action() : "")."
    			".($this->object_id ? $this->get_display_imp_action() : "")."
                ".($pmb_type_audit && $this->object_id ? $this->get_display_audit_action() : "")."
    		</div>
    		<div class='right'>
    			".($this->object_id ? $this->get_display_delete_action() : "")."
    		</div>";
        }
        
        return $display;
    }
}