/src/2.071.0/_document.class.php
PHP | 4436 lines | 2964 code | 825 blank | 647 comment | 609 complexity | 68d1099ca24657ebef2ab4932a0c84cb MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- // *************************************************************************************************************
- // CLASSE REGISSANT LES INFORMATIONS SUR UN DOCUMENT
- // *************************************************************************************************************
- abstract class document {
- protected $ref_doc;
- protected $lib_type_doc;
- protected $lib_type_printed;
- protected $date_creation;
- protected $id_etat_doc;
- protected $lib_etat_doc;
- protected $is_open;
- protected $code_affaire;
- protected $ref_contact;
- protected $contact;
- protected $nom_contact;
- protected $ref_adr_contact;
- protected $adresse_contact;
- protected $code_postal_contact;
- protected $ville_contact;
- protected $id_pays_contact;
- protected $pays_contact;
- protected $app_tarifs;
- protected $description;
- protected $contenu;
- protected $contenu_loaded;
- protected $contenu_materiel;
- protected $contenu_materiel_loaded;
- protected $contenu_service_abo;
- protected $contenu_service_abo_loaded;
- protected $contenu_service_conso;
- protected $contenu_service_conso_loaded;
- protected $liaisons;
- protected $liaisons_loaded;
- protected $liaisons_possibles;
- protected $liaisons_possibles_loaded;
-
- protected $code_file; //code md5 du nom du fichier pdf généré lors de l'envois du document
- protected $events;
- protected $events_loaded;
- protected $montant_ht;
- protected $montant_tva;
- protected $montant_ttc = -1; // Montant TTC du doc, = -1 quand non chargé
- protected $tvas;
- protected $ACCEPT_REGMT = 0;
- protected $reglements; // Règlements rapprochés à ce document
- protected $reglements_loaded;
- protected $montant_reglements; // Montant total des règlements (Inversé lorsqu'il s'agit d'emettre les règlements.)
- protected $montant_to_pay; // Montant restant à payer.
- protected $echeancier;
-
- protected $commerciaux; // commerciaux attribués à ce document
- protected $commerciaux_loaded;
-
- protected $code_pdf_modele; // Code du modèle utilisé pour l'impression
- protected $quantite_locked; // Les quantités pour ce document sont FIGEES
- public function __construct($ref_doc = "") {
- $this->ref_doc = $ref_doc;
- }
- // *************************************************************************************************************
- // FONCTIONS LIEES A L'OUVERTURE D'UN DOCUMENT
- // *************************************************************************************************************
- public function open_doc ($select = "", $left_join = "") {
- global $bdd;
- // Controle si la ref_document est précisée
- if (!$this->ref_doc) { return false; }
- $query = "SELECT d.ref_contact, d.nom_contact, d.ref_adr_contact, d.adresse_contact, d.code_postal_contact, d.ville_contact, d.id_pays_contact, d.app_tarifs, d.description,
- d.id_etat_doc, d.code_affaire, de.lib_etat_doc, de.is_open,
- dt.lib_type_doc, dt.lib_type_printed, pm.code_pdf_modele,
- d.date_creation_doc date_creation, d.code_file,
- p.pays pays_contact
- ".$select."
- FROM documents d
- LEFT JOIN documents_types dt ON d.id_type_doc = dt.id_type_doc
- LEFT JOIN doc_modeles_pdf dmp ON d.id_type_doc = dmp.id_type_doc && dmp.usage = 'defaut'
- LEFT JOIN pdf_modeles pm ON pm.id_pdf_modele = dmp.id_pdf_modele
- LEFT JOIN documents_etats de ON d.id_etat_doc = de.id_etat_doc
- LEFT JOIN pays p ON p.id_pays = d.id_pays_contact
- ".$left_join."
- WHERE d.ref_doc = '".$this->ref_doc."' ";
- $resultat = $bdd->query ($query);
- if (!$doc = $resultat->fetchObject()) { return false; }
- $this->ref_contact = $doc->ref_contact;
- $this->nom_contact = $doc->nom_contact;
- $this->ref_adr_contact = $doc->ref_adr_contact;
- $this->adresse_contact = $doc->adresse_contact;
- $this->code_postal_contact = $doc->code_postal_contact;
- $this->ville_contact = $doc->ville_contact;
- $this->id_pays_contact = $doc->id_pays_contact;
- $this->pays_contact = $doc->pays_contact;
- $this->app_tarifs = $doc->app_tarifs;
- $this->description = $doc->description;
- $this->id_etat_doc = $doc->id_etat_doc;
- $this->lib_etat_doc = $doc->lib_etat_doc;
- $this->is_open = $doc->is_open;
- $this->code_affaire = $doc->code_affaire;
- $this->lib_type_doc = $doc->lib_type_doc;
- $this->lib_type_printed = $doc->lib_type_printed;
- $this->code_pdf_modele = $doc->code_pdf_modele;
- $this->date_creation = $doc->date_creation;
- $this->code_file = $doc->code_file;
- $this->echeancier = new document_echeancier($this->getRef_doc(),$this);
- $this->quantite_locked = false;
- if(!$this->echeancier->exist()){
- $this->echeancier->create_from_ref_contact();
- }
-
- return $doc;
- }
- // *************************************************************************************************************
- // FONCTIONS LIEES A LA CREATION D'UN DOCUMENT
- // *************************************************************************************************************
- public function create_doc () {
- global $bdd;
- $this->pays_contact = "";
- // *************************************************
- // Type de document et etat
- $this->lib_type_doc = $this->LIB_TYPE_DOC;
- $this->id_etat_doc = $this->DEFAUT_ID_ETAT;
- $this->lib_etat_doc = $this->DEFAUT_LIB_ETAT;
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['id_etat_doc'])) {
- $this->id_etat_doc = $GLOBALS['_OPTIONS']['CREATE_DOC']['id_etat_doc'];
- }
- // *************************************************
- // Valeur par défaut des informations du document
- $this->check_profils ();
- $this->ref_contact = "";
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['ref_contact'])) {
- $this->ref_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['ref_contact'];
- }
-
- if ($this->ref_contact) {
- // Chargement des informations de ce contact
- $this->load_infos_contact ();
- }
- else {
- $this->load_defauts_infos_contact ();
- }
- if (!$this->app_tarifs) { $this->app_tarifs = "HT"; }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['code_affaire'])) {
- $this->code_affaire = $GLOBALS['_OPTIONS']['CREATE_DOC']['code_affaire'];
- }
-
- $this->description = "";
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['description'])) {
- $this->description = $GLOBALS['_OPTIONS']['CREATE_DOC']['description'];
- }
- // *************************************************
- // Verification qu'il n'y a pas eu d'erreur
- if (count($GLOBALS['_ALERTES'])) {
- return false;
- }
-
- //**************************************************
- //création du code file
- $this->code_file = md5(uniqid(rand(), true));
-
- // *************************************************
- // Création de la référence
- $reference = new reference ($this->DOC_ID_REFERENCE_TAG);
- $this->ref_doc = $reference->generer_ref();
- $this->echeancier = new document_echeancier($this->getRef_doc(),$this);
- // *************************************************
- // Insertion dans la base
- $bdd->beginTransaction();
- $query = "INSERT INTO documents (ref_doc, id_type_doc, id_etat_doc, code_affaire,
- ref_contact, nom_contact, ref_adr_contact, adresse_contact, code_postal_contact, ville_contact, id_pays_contact, app_tarifs, description, date_creation_doc, code_file)
- VALUES ('".$this->ref_doc."', '".$this->ID_TYPE_DOC."', '".$this->id_etat_doc."', '".$this->code_affaire."',
- ".ref_or_null($this->ref_contact).", '".addslashes($this->nom_contact)."',
- ".ref_or_null($this->ref_adr_contact).", '".addslashes($this->adresse_contact)."',
- '".$this->code_postal_contact."', '".addslashes($this->ville_contact)."',
- ".num_or_null($this->id_pays_contact).",
- '".$this->app_tarifs."', '".addslashes($this->description)."', NOW(), '".$this->code_file."' ) ";
- $bdd->exec ($query);
- //conditions de reglement
- if (($this->echeancier instanceof document_echeancier)) {
- if(!$this->echeancier->exist()){
- $this->echeancier->create_from_ref_contact();
- }
- }
-
- // *************************************************
- // Ajout de l'évennement de création
- $this->add_event(1);
-
- $bdd->commit();
- $GLOBALS['_INFOS']['ref_doc'] = $this->ref_doc;
- // *************************************************
- // Informations complémentaires
- $this->date_creation = date ("Y-m-d H:i:s");
- return true;
- }
- // Charge les informations supplémentaires du contact
- protected function load_infos_contact () {
- //conditions de reglement
- if (($this->echeancier instanceof document_echeancier)) {
- if(!$this->echeancier->exist()){
- $this->echeancier->create_from_ref_contact();
- }
- }
- // Nom
- $this->define_nom_contact ();
- // Adresse
- $this->define_adresse_contact ();
- // Préférences d'affichage du tarif
- $this->define_aff_tarif ();
- }
- protected function load_defauts_infos_contact () {
- $this->define_adresse_contact ();
- }
- protected function load_infos_contact_client () {
- global $CLIENT_ID_PROFIL;
- if (!is_object($this->contact)) { $this->contact = new contact ($this->ref_contact); }
- if (!$this->contact->charger_profiled_infos($CLIENT_ID_PROFIL)) {
- // Creation des informations de profil CLIENT
- $infos_profil['id_profil'] = $CLIENT_ID_PROFIL;
- $this->contact->create_profiled_infos ($infos_profil);
- }
- }
- protected function load_infos_contact_fournisseur () {
- global $FOURNISSEUR_ID_PROFIL;
- if (!is_object($this->contact)) { $this->contact = new contact ($this->ref_contact); }
- if (!$this->contact->charger_profiled_infos($FOURNISSEUR_ID_PROFIL)) {
- // Creation des informations de profil FOURNISSEUR
- $infos_profil['id_profil'] = $FOURNISSEUR_ID_PROFIL;
- $this->contact->create_profiled_infos ($infos_profil);
- }
- }
- // Défini le nom du contact
- protected function define_nom_contact () {
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['nom_contact'])) {
- $this->nom_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['nom_contact'];
- }
- else {
- $this->contact = new contact ($this->ref_contact);
- $this->nom_contact = $this->contact->getLib_civ_court()." ".$this->contact->getNom();
- }
- }
- // Renvoie l'adresse a utiliser dans le document pour un contact donné
- protected function define_adresse_contact () {
- global $bdd;
- global $DEFAUT_ID_PAYS;
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['ref_adr_contact'])) {
- $this->ref_adr_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['ref_adr_contact'];
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['adresse_contact'])) {
- $this->adresse_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['adresse_contact'];
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['code_postal_contact'])) {
- $this->code_postal_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['code_postal_contact'];
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['ville_contact'])) {
- $this->ville_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['ville_contact'];
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['id_pays_contact'])) {
- $this->id_pays_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['id_pays_contact'];
- }
-
-
- if (!$this->ref_adr_contact && !$this->adresse_contact && !$this->code_postal_contact && !$this->ville_contact && !$this->id_pays_contact) {
- // Sélection de la première Adresse
- $query = "SELECT ref_adresse, text_adresse, code_postal, ville, a.id_pays, p.pays
- FROM adresses a
- LEFT JOIN pays p ON a.id_pays = p.id_pays
- WHERE ref_contact = '".$this->ref_contact."' && ordre = 1 ";
- $resultat = $bdd->query ($query);
- if (!$a = $resultat->fetchObject()) { return false; }
- $this->ref_adr_contact = $a->ref_adresse;
- $this->adresse_contact = $a->text_adresse ;
- $this->code_postal_contact = $a->code_postal ;
- $this->ville_contact = $a->ville ;
- $this->id_pays_contact = $a->id_pays ;
- $this->pays_contact = $a->pays ;
- }
- if (!$this->id_pays_contact) {$this->id_pays_contact = $DEFAUT_ID_PAYS;}
-
- return true;
- }
- // Renvoie l'adresse a utiliser dans le document pour un contact donné
- function define_adresse_contact_et_livraison () {
- global $bdd;
- global $DEFAUT_ID_PAYS;
- $adresse_contact_ok = $adresse_livraison_ok = 0;
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['ref_adr_contact'])) {
- $this->ref_adr_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['ref_adr_contact'];
- $adresse_contact_ok = 1;
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['adresse_contact'])) {
- $this->adresse_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['adresse_contact'];
- $adresse_contact_ok = 1;
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['code_postal_contact'])) {
- $this->code_postal_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['code_postal_contact'];
- $adresse_contact_ok = 1;
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['ville_contact'])) {
- $this->ville_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['ville_contact'];
- $adresse_contact_ok = 1;
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['id_pays_contact'])) {
- $this->id_pays_contact = $GLOBALS['_OPTIONS']['CREATE_DOC']['id_pays_contact'];
- $adresse_contact_ok = 1;
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['ref_adr_livraison'])) {
- $this->ref_adr_livraison = $GLOBALS['_OPTIONS']['CREATE_DOC']['ref_adr_livraison'];
- $adresse_livraison_ok = 1;
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['adresse_livraison'])) {
- $this->adresse_livraison = $GLOBALS['_OPTIONS']['CREATE_DOC']['adresse_livraison'];
- $adresse_livraison_ok = 1;
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['code_postal_livraison'])) {
- $this->code_postal_livraison = $GLOBALS['_OPTIONS']['CREATE_DOC']['code_postal_livraison'];
- $adresse_livraison_ok = 1;
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['ville_livraison'])) {
- $this->ville_livraison = $GLOBALS['_OPTIONS']['CREATE_DOC']['ville_livraison'];
- $adresse_livraison_ok = 1;
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['id_pays_livraison'])) {
- $this->id_pays_livraison = $GLOBALS['_OPTIONS']['CREATE_DOC']['id_pays_livraison'];
- $adresse_livraison_ok = 1;
- }
-
- if (!$adresse_livraison_ok && ($_SESSION['magasin']->getMode_vente() == "VAC")) {
- $this->ref_adr_livraison = "NULL";
- $this->adresse_livraison = $_SESSION['magasin']->getLib_magasin ();
- }
-
- if ( !$adresse_contact_ok || !$adresse_livraison_ok) {
- // Sélection des adresses prédéfinies
- $query = "SELECT ref_adr_livraison, a1.text_adresse ta1, a1.code_postal cp1, a1.ville v1, a1.id_pays ip1, p1.pays p1,
- ref_adr_facturation, a2.text_adresse ta2, a2.code_postal cp2, a2.ville v2, a2.id_pays ip2, p2.pays p2
- FROM annu_client ac
- LEFT JOIN adresses a1 ON ac.ref_adr_livraison = a1.ref_adresse
- LEFT JOIN pays p1 ON a1.id_pays = p1.id_pays
- LEFT JOIN adresses a2 ON ac.ref_adr_facturation = a2.ref_adresse
- LEFT JOIN pays p2 ON a2.id_pays = p2.id_pays
- WHERE ac.ref_contact = '".$this->ref_contact."' ";
- $resultat = $bdd->query ($query);
- if (!$a = $resultat->fetchObject()) { return false; }
-
- if (!$adresse_contact_ok) {
- $this->ref_adr_contact = $a->ref_adr_facturation;
- $this->adresse_contact = $a->ta2;
- $this->code_postal_contact = $a->cp2 ;
- $this->ville_contact = $a->v2 ;
- $this->id_pays_contact = $a->ip2 ;
- $this->pays_contact = $a->p2 ;
- }
- if (!$adresse_livraison_ok || ($_SESSION['magasin']->getMode_vente() != "VAC")) {
- $this->ref_adr_livraison = $a->ref_adr_livraison;
- $this->adresse_livraison = $a->ta1;
- $this->code_postal_livraison = $a->cp1 ;
- $this->ville_livraison = $a->v1 ;
- $this->id_pays_livraison = $a->ip1 ;
- $this->pays_livraison = $a->p1 ;
- }
- }
- if (!$this->id_pays_contact) {$this->id_pays_contact = $DEFAUT_ID_PAYS;}
- if (!$this->id_pays_livraison) {$this->id_pays_livraison = $DEFAUT_ID_PAYS;}
- return true;
- }
- // Renvoie le texte précis de l'adresse qui sera affiché
- protected function define_text_adresse ($text_adresse, $code_postal, $ville, $id_pays, $pays) {
- global $DEFAUT_ID_PAYS;
- $adresse_contact = $text_adresse;
- if ($code_postal || $ville) {
- $adresse_contact .= "\n".$code_postal." ".$ville;
- }
- if ($id_pays && $id_pays != $DEFAUT_ID_PAYS ) {
- $adresse_contact .= "\n".$pays;
- }
-
- return $adresse_contact;
- }
- // Renvoie le type d'affichage des tarifs a utiliser (HT ou TTC) pour le document
- protected function define_aff_tarif () {
- $this->define_client_aff_tarif ();
- }
- function define_client_aff_tarif () {
- global $DEFAUT_APP_TARIFS_CLIENT;
- global $CLIENT_ID_PROFIL;
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['app_tarifs'])) {
- $this->app_tarifs = $GLOBALS['_OPTIONS']['CREATE_DOC']['app_tarifs'];
- }
- else {
- $tmp = $this->contact->getProfil($CLIENT_ID_PROFIL);
- $this->app_tarifs = $tmp->getApp_tarifs();
- }
- }
- function define_fournisseur_aff_tarif () {
- global $DEFAUT_APP_TARIFS_FOURNISSEUR;
- global $FOURNISSEUR_ID_PROFIL;
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['app_tarifs'])) {
- $this->app_tarifs = $GLOBALS['_OPTIONS']['CREATE_DOC']['app_tarifs'];
- }
- else {
- $tmp = $this->contact->getProfil($FOURNISSEUR_ID_PROFIL);
- $this->app_tarifs = $tmp->getApp_tarifs();
- }
- }
- // *************************************************************************************************************
- // FONCTIONS LIEES A LA MODIFICATION D'UN DOCUMENT
- // *************************************************************************************************************
- // Changement du contact d'un document
- public function maj_contact ($ref_contact) {
- global $bdd;
- global $DEFAUT_APP_TARIFS_CLIENT;
- global $DEFAUT_ID_PAYS;
- if ($ref_contact == $this->ref_contact) { return false; }
- $old_ref_contact = $this->ref_contact;
- $old_nom_contact = $this->nom_contact;
- if (!$ref_contact) {$this->ref_contact = "";}
-
- if ($ref_contact) {
- $this->ref_contact = $ref_contact;
- // Chargement des informations de ce contact
- $this->contact = new contact ($ref_contact);
- $this->load_infos_contact ();
- }
- if (!is_object($this->contact) || !$this->contact->getRef_contact()) {
- $this->ref_contact = "";
- $this->nom_contact = "";
- $this->ref_adr_contact = "";
- $this->adresse_contact = "";
- $this->code_postal_contact = "";
- $this->ville_contact = "";
- $this->id_pays_contact = $DEFAUT_ID_PAYS;
- $this->app_tarifs = $DEFAUT_APP_TARIFS_CLIENT;
- }
- // *************************************************
- // MAJ de la base
- $bdd->beginTransaction();
- $query = "UPDATE documents
- SET ref_contact = ".ref_or_null($this->ref_contact).", nom_contact = '".addslashes($this->nom_contact)."',
- ref_adr_contact = ".ref_or_null($this->ref_adr_contact).",
- adresse_contact = '".addslashes($this->adresse_contact)."',
- code_postal_contact = '".$this->code_postal_contact."',
- ville_contact = '".addslashes($this->ville_contact)."',
- id_pays_contact = ".num_or_null($this->id_pays_contact).",
- app_tarifs = '".$this->app_tarifs."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
-
- // MAJ du contact pour les règlements de ce document qui ne règlent pas d'autres documents du même type
- $query = "SELECT rd.ref_reglement, COUNT(rd.ref_doc) as nb_docs
- FROM reglements_docs rd
- LEFT JOIN documents d ON d.ref_doc = rd.ref_doc
- WHERE rd.ref_reglement IN (
- SELECT ref_reglement
- FROM reglements_docs rd
- WHERE rd.ref_doc = '".$this->ref_doc."'
- )
- && rd.liaison_valide = '1'
- GROUP BY rd.ref_reglement";
- $resultat = $bdd->query ($query);
-
- $rgmts_to_update = $rgmts_to_deli = array();
- while ($rgmt = $resultat->fetchObject()) {
- //echo $rgmt->ref_reglement;
- if ($rgmt->nb_docs > 1) { $rgmts_to_deli[] = $rgmt->ref_reglement; }
- else { $rgmts_to_update[] = $rgmt->ref_reglement; }
- }
- if ($rgmts_to_update) {
- $list_to_update = "''";
- foreach ($rgmts_to_update as $ref_rgmt) { $list_to_update .= ",'".$ref_rgmt."'"; }
- $query = "UPDATE reglements SET ref_contact = ".ref_or_null($this->ref_contact)."
- WHERE ref_reglement IN (".$list_to_update.")";
- $bdd->exec ($query);
- }
- if ($rgmts_to_deli) {
- $list_to_deli = "''";
- foreach ($rgmts_to_deli as $ref_rgmt) { $list_to_deli .= ",'".$ref_rgmt."'"; }
- $query = "DELETE FROM reglements_docs
- WHERE ref_reglement IN (".$list_to_deli.") && ref_doc = '".$this->ref_doc."' ";
- $resultat = $bdd->query ($query);
- if ($resultat->rowCount()) { $this->check_etat_reglement (); }
- }
- // Evenement
- if ($old_ref_contact) {
- $this->add_event(6, "Ancien contact : ".$old_nom_contact." (".$old_ref_contact.")\n Nouveau contact : ".$this->nom_contact." (".$this->ref_contact.")");
- }
- $bdd->commit();
- return true;
- }
- public function maj_nom_contact ($nom_contact) {
- global $bdd;
- $this->nom_contact = $nom_contact;
- // *************************************************
- // MAJ de la base
- $query = "UPDATE documents
- SET nom_contact = '".addslashes($this->nom_contact)."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- }
- public function maj_adresse_contact ($ref_adresse) {
- global $bdd;
- global $DEFAUT_ID_PAYS;
- if (is_numeric($ref_adresse)) {
- $query = "SELECT lib_stock FROM stocks
- WHERE id_stock = '".addslashes($ref_adresse)."' ";
- $resultat = $bdd->query ($query);
- if (!$s = $resultat->fetchObject()) { return false; }
- $this->ref_adr_contact = "NULL";
- $this->adresse_contact = $s->lib_stock;
- $this->code_postal_contact = "";
- $this->ville_contact = "";
- $this->id_pays_contact = $DEFAUT_ID_PAYS;
- $this->pays_contact = "";
- if (isset($_SESSION['stocks'][$ref_adresse])) {
- $adresse = $_SESSION['stocks'][$ref_adresse]->getAdresse ();
- $this->id_pays_contact = $adresse->getId_pays();
- }
- }
- else {
- // Sélection de l'Adresse
- $query = "SELECT ref_adresse, text_adresse, code_postal, ville, a.id_pays, p.pays
- FROM adresses a
- LEFT JOIN pays p ON a.id_pays = p.id_pays
- WHERE ref_adresse = '".$ref_adresse."' ";
- $resultat = $bdd->query ($query);
- if (!$a = $resultat->fetchObject()) { return false; }
- $this->ref_adr_contact = $a->ref_adresse;
- $this->adresse_contact = $a->text_adresse;
- $this->code_postal_contact = $a->code_postal;
- $this->ville_contact = $a->ville;
- $this->id_pays_contact = $a->id_pays;
- $this->pays_contact = $a->pays;
- }
- // *************************************************
- // MAJ de la base
- $query = "UPDATE documents
- SET ref_adr_contact = ".ref_or_null($this->ref_adr_contact).",
- adresse_contact = '".addslashes($this->adresse_contact)."',
- code_postal_contact = '".($this->code_postal_contact)."',
- ville_contact = '".addslashes($this->ville_contact)."',
- id_pays_contact = ".num_or_null($this->id_pays_contact)."
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- return true;
- }
- public function maj_text_adresse_contact ($text_adresse) {
- global $bdd;
- $this->adresse_contact = $text_adresse;
- // *************************************************
- // MAJ de la base
- $query = "UPDATE documents
- SET adresse_contact = '".addslashes($this->adresse_contact)."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- }
- public function maj_text_code_postal_contact ($text_code_postal) {
- global $bdd;
- $this->code_postal_contact = $text_code_postal;
- // *************************************************
- // MAJ de la base
- $query = "UPDATE documents
- SET code_postal_contact = '".$this->code_postal_contact."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- }
- public function maj_text_ville_contact ($text_ville) {
- global $bdd;
- $this->ville_contact = $text_ville;
- // *************************************************
- // MAJ de la base
- $query = "UPDATE documents
- SET ville_contact = '".addslashes($this->ville_contact)."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- }
- public function maj_text_id_pays_contact ($text_id_pays) {
- global $bdd;
- $this->id_pays_contact = $text_id_pays;
- // *************************************************
- // MAJ de la base
- $query = "UPDATE documents
- SET id_pays_contact = ".num_or_null($this->id_pays_contact)."
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- }
- public function maj_adresse_livraison ($ref_adresse) {
- global $bdd;
- global $DEFAUT_ID_PAYS;
- if (is_numeric($ref_adresse)) {
- $query = "SELECT lib_stock FROM stocks
- WHERE id_stock = '".addslashes($ref_adresse)."' ";$resultat = $bdd->query ($query);
- if (!$s = $resultat->fetchObject()) { return false; }
- $this->ref_adr_livraison = "NULL";
- $this->adresse_livraison = $s->lib_stock;
- $this->code_postal_livraison = "" ;
- $this->ville_livraison = "" ;
- $this->id_pays_livraison = $DEFAUT_ID_PAYS ;
- $this->pays_livraison = "" ;
- if (isset($_SESSION['stocks'][$ref_adresse])) {
- $adresse = $_SESSION['stocks'][$ref_adresse]->getAdresse ();
- $this->id_pays_livraison = $adresse->getId_pays();
- }
- }
- else {
- // Sélection de l'Adresse
- $query = "SELECT ref_adresse, text_adresse, code_postal, ville, a.id_pays, p.pays
- FROM adresses a
- LEFT JOIN pays p ON a.id_pays = p.id_pays
- WHERE ref_adresse = '".$ref_adresse."' ";
- $resultat = $bdd->query ($query);
- if (!$a = $resultat->fetchObject()) { return false; }
- $this->ref_adr_livraison = $a->ref_adresse;
- $this->adresse_livraison = $a->text_adresse ;
- $this->code_postal_livraison = $a->code_postal ;
- $this->ville_livraison = $a->ville ;
- $this->id_pays_livraison = $a->id_pays ;
- $this->pays_livraison = $a->pays ;
- }
- // *************************************************
- // MAJ de la base
- $query = "UPDATE doc_".strtolower($this->CODE_DOC)."
- SET ref_adr_livraison = ".ref_or_null($this->ref_adr_livraison).",
- adresse_livraison = '".addslashes($this->adresse_livraison)."',
- code_postal_livraison = '".$this->code_postal_livraison."',
- ville_livraison = '".addslashes($this->ville_livraison)."',
- id_pays_livraison = ".num_or_null($this->id_pays_livraison)."
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- return true;
- }
- public function maj_text_adresse_livraison ($text_adresse) {
- global $bdd;
- $this->adresse_livraison = $text_adresse;
- // *************************************************
- // MAJ de la base
- $query = "UPDATE doc_".strtolower($this->CODE_DOC)."
- SET adresse_livraison = '".addslashes($this->adresse_livraison)."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- return true;
- }
- public function maj_text_code_postal_livraison ($text_code_postal) {
- global $bdd;
- $this->code_postal_livraison = $text_code_postal;
- // *************************************************
- // MAJ de la base
- $query = "UPDATE doc_".strtolower($this->CODE_DOC)."
- SET code_postal_livraison = '".$this->code_postal_livraison."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- return true;
- }
- public function maj_text_ville_livraison ($text_ville) {
- global $bdd;
- $this->ville_livraison = $text_ville;
- // *************************************************
- // MAJ de la base
- $query = "UPDATE doc_".strtolower($this->CODE_DOC)."
- SET ville_livraison = '".addslashes($this->ville_livraison)."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- return true;
- }
- public function maj_text_id_pays_livraison ($text_id_pays) {
- global $bdd;
- $this->id_pays_livraison = $text_id_pays;
- // *************************************************
- // MAJ de la base
- $query = "UPDATE doc_".strtolower($this->CODE_DOC)."
- SET id_pays_livraison = ".num_or_null($this->id_pays_livraison)."
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- return true;
- }
- static function maj_description ($ref_doc, $new_description) {
- global $bdd;
-
- $query = "UPDATE documents SET description = '".addslashes($new_description)."'
- WHERE ref_doc = '".$ref_doc."' ";
- $bdd->exec ($query);
-
- // $this->description = $new_description;
- }
- function maj_app_tarifs ($new_app_tarifs) {
- global $bdd;
- global $CLIENT_ID_PROFIL;
- // Controle
- if ($new_app_tarifs != "HT") {
- $new_app_tarifs == "TTC";
- }
- $this->app_tarifs = $new_app_tarifs;
-
- // Maj de la base de données
- $query = "UPDATE documents SET app_tarifs = '".$this->app_tarifs."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
-
- //fonction de mise à jour de l'app_tarif du contact en cas de changement d'app_tarif du document par défaut le profil client (seul les class de doc spéciales fournisseur forceront l'app_tarifs du profil fournisseur
- if (!is_object($this->contact)) { $this->contact = new contact ($this->ref_contact); }
- if ($this->contact->charger_profiled_infos($CLIENT_ID_PROFIL)) {
- $profil_tmp = $this->contact->getProfil($CLIENT_ID_PROFIL);
- $profil_tmp->maj_app_tarifs ($this->app_tarifs);
- }
- }
- public function maj_id_stock ($id_stock, $lib_var = "") {
- global $bdd;
- if (!$lib_var) { $lib_var = "id_stock"; }
- // Vérification de l'existence du stock
- $found = 0;
- foreach ($_SESSION['stocks'] as $stock) {
- if ($stock->getId_stock() != $id_stock) { continue; }
- $found = 1;
- break;
- }
- if (!$found) {
- $GLOBALS['_ALERTES']['bad_'.$lib_var] = 1;
- }
- // Vérification de la possibilité de changer l'id_stock (expédiant ou recevant)
- if (!$this->is_open) {
- $GLOBALS['_ALERTES']['doc_is_closed'] = 1;
- }
- if (count($GLOBALS['_ALERTES'])) {
- return false;
- }
- $this->{$lib_var} = $id_stock;
- // *************************************************
- // MAJ de la base
- $query = "UPDATE doc_".strtolower($this->CODE_DOC)."
- SET ".$lib_var." = '".$this->{$lib_var}."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- // *************************************************
- // Retour des informations
- $GLOBALS['_INFOS'][$lib_var] = $this->{$lib_var};
- return true;
- }
- // Fusion de documents
- public function fusion_doc ($second_ref_doc) {
-
- global $bdd;
- if (!isset($second_ref_doc)) { return false;}
-
- $second_document = open_doc($second_ref_doc);
-
- if (!$this->check_allow_fusion ($second_document)) { return false; }
-
- //Début de la fusion
-
- $GLOBALS['_OPTIONS']['FUSION'] = 1;
-
- //insertion de la ligne d'info
- $infos['type_of_line'] = "information";
- $infos['titre'] = "Contenu issu de la fusion avec ".$second_document->getRef_doc ();
- $infos['texte'] = "";
- $infos['visible'] = 0;
- $this->add_line ($infos);
-
- //copie du contenu
- $second_document->copie_content ($this);
-
-
- //changement des liaisons existantes du second document vers le premier
- $query = "UPDATE documents_liaisons SET ref_doc_destination = '".$this->ref_doc."'
- WHERE ref_doc_destination = '".$second_document->getRef_doc ()."' ";
- $bdd->exec ($query);
-
- $query = "UPDATE documents_liaisons SET ref_doc_source = '".$this->ref_doc."'
- WHERE ref_doc_source = '".$second_document->getRef_doc ()."' ";
- $bdd->exec ($query);
-
- //liaison non active prouvant la liaison entre les docs
- $this->link_from_doc_set_active ($second_document->getRef_doc (), 0) ;
-
- //renvoi des règlements vers le premier document
- $query = "UPDATE reglements_docs SET ref_doc = '".$this->ref_doc."'
- WHERE ref_doc = '".$second_document->getRef_doc ()."' ";
- $bdd->exec ($query);
- // Annulation du second document
- $second_document->maj_etat_doc ($this->ID_ETAT_ANNULE);
-
- $this->add_event(5, "avec ".$second_document->getRef_doc ());
- $second_document->add_event(5, "vers ".$this->ref_doc);
-
- return true;
- }
- // Liste des documents pouvant être fusionner
- public function check_allow_fusion ($second_document) {
-
- return true;
- }
- // Liste des documents pouvant être fusionner
- public function liste_doc_fusion () {
-
- return true;
- }
- // *************************************************************************************************************
- // FONCTIONS LIEES A LA MODIFICATION DE L'ETAT D'UN DOCUMENT
- // *************************************************************************************************************
- // Changement de l'état du document
- final public function maj_etat_doc ($new_etat_doc) {
- global $bdd;
- if ($this->id_etat_doc == $new_etat_doc) { return false; }
- if (!$new_etat_doc = $this->check_maj_etat($new_etat_doc)) { return false; }
- // Mise à jour des liaisons avec d'autres documents le cas échéant
- if ($new_etat_doc == $this->ID_ETAT_ANNULE) {
- $this->maj_etat_liaisons(0);
- }
- elseif ($this->id_etat_doc == $this->ID_ETAT_ANNULE) {
- $this->maj_etat_liaisons(1);
- }
-
- // Mise à jour des liaisons avec les règlements le cas échéant
- if ($new_etat_doc == $this->ID_ETAT_ANNULE) {
- $this->maj_etat_reglements(0);
- }
- elseif ($this->id_etat_doc == $this->ID_ETAT_ANNULE) {
- $this->maj_etat_reglements(1);
- }
- // Action a effectuer avant toute chose (Controles, etc.)
- $this->action_before_maj_etat ($new_etat_doc);
- // Sélection du libellé du nouvel état
- $query = "SELECT lib_etat_doc FROM documents_etats
- WHERE id_etat_doc = '".$new_etat_doc."' ";
- $resultat = $bdd->query ($query);
- $info = $resultat->fetchObject();
- // Changements sur l'objet
- $old_etat_doc = $this->id_etat_doc;
- $this->id_etat_doc = $new_etat_doc;
- $this->lib_etat_doc = $info->lib_etat_doc;
- // *************************************************
- // Maj dans la BDD
- $query = "UPDATE documents SET id_etat_doc = '".$new_etat_doc."'
- WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
-
- // Enregistrement de l'évennement
- $id_event_type = 2;
- $event = $this->lib_etat_doc;
- $this->add_event($id_event_type, $event);
- // Action a effectuer apres la mise a jour de l'etat.
- $this->action_after_maj_etat ($old_etat_doc);
-
- return true;
- }
- // Vérification de la possibilité de changer l'état du document
- protected function check_maj_etat ($new_etat_doc) {
- if (!is_numeric($new_etat_doc)) { return false; }
- return $new_etat_doc;
- }
- // Action avant de changer l'état du document
- protected function action_before_maj_etat ($new_etat_doc) {
- return true;
- }
- // Action après de changer l'état du document
- protected function action_after_maj_etat ($old_etat_doc) {
- return true;
- }
- protected function maj_etat_liaisons ($active = 1) {
- global $bdd;
- $query = "UPDATE documents_liaisons SET active = '".$active."'
- WHERE ref_doc_source = '".$this->ref_doc."' || ref_doc_destination = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- return true;
- }
- // *************************************************************************************************************
- // FONCTIONS DE GESTION DU CONTENU
- // *************************************************************************************************************
- // Chargement du contenu du document
- public function charger_contenu () {
- global $bdd;
- global $CALCUL_TARIFS_NB_DECIMALS;
- global $TARIFS_NB_DECIMALES;
- global $GESTION_SN;
- global $DOC_AFF_QTE_SN;
- $query_infos_supp = $this->doc_line_infos_supp ();
- // *****************************************
- // Chargement du contenu
- $this->contenu = $tmp_contenu = array();
- $query = "SELECT dl.ref_doc_line, dl.ref_article, dl.lib_article, dl.desc_article,
- dl.qte, round(dl.pu_ht,".$CALCUL_TARIFS_NB_DECIMALS.") as pu_ht, dl.remise, dl.tva,
- dl.ordre, dl.ref_doc_line_parent, dl.visible, dl.pa_ht, dl.pa_forced,
- a.ref_oem, a.ref_interne, a.id_valo, a.valo_indice, a.gestion_sn, ac.modele, a.lot, av.abrev_valo
- ".$query_infos_supp['select']."
- FROM docs_lines dl
- LEFT JOIN articles a ON dl.ref_article = a.ref_article
- LEFT JOIN articles_valorisations av ON av.id_valo = a.id_valo
- LEFT JOIN art_categs ac ON a.ref_art_categ = ac.ref_art_categ
- ".$query_infos_supp['left_join']."
- WHERE ref_doc = '".$this->ref_doc."'
- ORDER BY ordre ";
- $resultat = $bdd->query ($query);
- while ($doc_line = $resultat->fetchObject()) {
- $doc_line->type_of_line = define_type_of_line($doc_line->ref_article);
- $tmp_contenu[] = $doc_line;
- }
- for ($i=0; $i<count($tmp_contenu); $i++) {
- if ($tmp_contenu[$i]->ref_doc_line_parent) { continue; }
- $this->contenu[] = $tmp_contenu[$i];
- for ($j=0; $j<count($tmp_contenu); $j++) {
- if ($tmp_contenu[$j]->ref_doc_line_parent != $tmp_contenu[$i]->ref_doc_line) { continue; }
- $this->contenu[] = $tmp_contenu[$j];
- }
- }
- $this->contenu_loaded = true;
- // *****************************************
- // Calcul des montants HT et TTC, des TVAS et des TAXES
- $this->montant_ht = $this->montant_tva = 0;
- $this->tvas = array();
- for ($i=0; $i<count($this->contenu); $i++) {
- if ( $this->contenu[$i]->type_of_line != "article" || !$this->contenu[$i]->visible) {
- continue;
- }
- $this->contenu[$i]->pu_ht = round($this->contenu[$i]->pu_ht, $CALCUL_TARIFS_NB_DECIMALS);
- $montant_ht = round ($this->contenu[$i]->pu_ht * $this->contenu[$i]->qte * (1-$this->contenu[$i]->remise/100), $CALCUL_TARIFS_NB_DECIMALS);
- $tva = round($montant_ht * ($this->contenu[$i]->tva/100), $TARIFS_NB_DECIMALES) ;
- $this->montant_ht += $montant_ht;
- $this->montant_tva += $tva;
- if (!isset($this->tvas[$this->contenu[$i]->tva])) { $this->tvas[$this->contenu[$i]->tva] = 0; }
- $this->tvas[$this->contenu[$i]->tva] += $tva;
- }
- $this->montant_ttc = $this->montant_ht + $this->montant_tva;
- // *****************************************
- // Chargement des numéros de serie
- if (!$GESTION_SN || !$this->GESTION_SN) { return true; }
- $query_sn_infos_supp = $this->doc_line_sn_infos_supp ();
- $numeros = array();
- $contenu_liste = "";
- foreach ($this->contenu as $doc_line) {
- if (!$doc_line->gestion_sn) { continue; }
- if ($doc_line->gestion_sn == 2) {
- unset($GLOBALS['_OPTIONS']['CREATE_DOC']['no_charge_all_sn']);
- $GLOBALS['_OPTIONS']['CREATE_DOC']['group_sn'] = 1;
- }
- if ($contenu_liste) {$contenu_liste .= ",";}
- $contenu_liste .= "'".$doc_line->ref_doc_line."'";
- }
- if (!$contenu_liste) { return true; }
- $query = "SELECT dls.ref_doc_line, dls.numero_serie, dls.sn_qte ".$query_sn_infos_supp['select']."
- FROM docs_lines_sn dls ".$query_sn_infos_supp['left_join']."
- WHERE dls.ref_doc_line IN (".$contenu_liste.")
- ORDER BY dls.numero_serie ASC";
-
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['no_charge_all_sn']) ) {
- $query .= " LIMIT ".($DOC_AFF_QTE_SN+1);
-
- }
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['group_sn']) ) {
-
- $query = "SELECT dls.ref_doc_line, dls.numero_serie, dls.sn_qte
- FROM docs_lines_sn dls
- WHERE dls.ref_doc_line IN (".$contenu_liste.")
- ORDER BY dls.numero_serie ASC";
-
- }
- $resultat = $bdd->query ($query);
- while ($sn = $resultat->fetchObject()) { $numeros[] = $sn; }
- // Association des numéros de série au contenu
- for ($i=0; $i<count($this->contenu); $i++) {
- // Création du tableau de numéros de série
- if ($this->contenu[$i]->gestion_sn) { $this->contenu[$i]->sn = array(); }
- // Remplissage du tableau
- foreach ($numeros as $sn) {
- if ($this->contenu[$i]->ref_doc_line != $sn->ref_doc_line) { continue; }
- $this->contenu[$i]->sn[] = $sn;
- }
- }
- return true;
- }
- protected function charger_line ($ref_doc_line) {
- global $bdd;
- global $GESTION_SN;
- global $CALCUL_TARIFS_NB_DECIMALS;
- $query_infos_supp = $this->doc_line_infos_supp ();
- // Sélection des informations
- $query = "SELECT dl.ref_doc_line, dl.ref_article, dl.lib_article, dl.desc_article,
- dl.qte, round(dl.pu_ht,".$CALCUL_TARIFS_NB_DECIMALS.") as pu_ht, dl.remise, dl.tva,
- dl.ordre, dl.ref_doc_line_parent, dl.visible, dl.pa_ht, dl.pa_forced,
- a.ref_oem, a.ref_interne, a.id_valo, a.valo_indice, a.gestion_sn, ac.modele, a.lot, av.abrev_valo
- ".$query_infos_supp['select']."
- FROM docs_lines dl
- LEFT JOIN articles a ON dl.ref_article = a.ref_article
- LEFT JOIN articles_valorisations av ON av.id_valo = a.id_valo
- LEFT JOIN art_categs ac ON a.ref_art_categ = ac.ref_art_categ
- ".$query_infos_supp['left_join']."
- WHERE dl.ref_doc_line = '".addslashes($ref_doc_line)."' ";
- $bdd->query ($query);
- $resultat = $bdd->query ($query);
- if (!$doc_line = $resultat->fetchObject()) { return false; }
- $doc_line->type_of_line = define_type_of_line($doc_line->ref_article);
- // *****************************************
- // Chargement des numéros de serie
- if (!$GESTION_SN || !$this->GESTION_SN || !$doc_line->gestion_sn) { return $doc_line; }
- $query_sn_infos_supp = $this->doc_line_sn_infos_supp ();
- $doc_line->sn = array();
- $query = "SELECT dls.ref_doc_line, dls.numero_serie ".$query_sn_infos_supp['select']."
- FROM docs_lines_sn dls ".$query_sn_infos_supp['left_join']."
- WHERE dls.ref_doc_line = '".$ref_doc_line."' ";
- if ($doc_line->gestion_sn == 2) {
-
- $query = "SELECT dls.ref_doc_line, dls.numero_serie
- FROM docs_lines_sn dls
- WHERE dls.ref_doc_line = '".$ref_doc_line."' ";
- }
- $resultat = $bdd->query ($query);
- while ($sn = $resultat->fetchObject()) { $doc_line->sn[] = $sn; }
- return $doc_line;
- }
- // Chargement du contenu "matériel" du document
- public function charger_contenu_materiel () {
- global $bdd;
- global $GESTION_SN;
- $query_infos_supp = $this->doc_line_infos_supp ();
- // *****************************************
- // Chargement du contenu
- $this->contenu_materiel = array();
- $query = "SELECT dl.ref_doc_line, dl.ref_article, dl.qte, dl.pa_ht, dl.pa_forced, a.gestion_sn
- ".$query_infos_supp['select']."
- FROM docs_lines dl
- LEFT JOIN articles a ON dl.ref_article = a.ref_article
- LEFT JOIN art_categs ac ON a.ref_art_categ = ac.ref_art_categ
- ".$query_infos_supp['left_join']."
- WHERE ref_doc = '".$this->ref_doc."' && a.modele = 'materiel' && a.lot != '2'";
- $resultat = $bdd->query ($query);
- while ($doc_line = $resultat->fetchObject()) {
- $this->contenu_materiel[] = $doc_line;
- }
- $this->contenu_materiel_loaded = true;
- // *****************************************
- // Chargement des numéros de serie
- if (!$GESTION_SN || !$this->GESTION_SN) { return true; }
- $query_sn_infos_supp = $this->doc_line_sn_infos_supp ();
- $contenu_liste = "''";
- foreach ($this->contenu_materiel as $doc_line) {
- if (!$doc_line->gestion_sn) { continue; }
- if ($doc_line->gestion_sn == 2) {
- unset($GLOBALS['_OPTIONS']['CREATE_DOC']['no_charge_all_sn']);
- $GLOBALS['_OPTIONS']['CREATE_DOC']['group_sn'] = 1;
- }
- if ($contenu_liste) {$contenu_liste .= ",";}
- $contenu_liste .= "'".$doc_line->ref_doc_line."'";
- }
- if (!$contenu_liste) { return true; }
- $query = "SELECT dls.ref_doc_line, dls.numero_serie, dls.sn_qte ".$query_sn_infos_supp['select']."
- FROM docs_lines_sn dls ".$query_sn_infos_supp['left_join']."
- WHERE dls.ref_doc_line IN (".$contenu_liste.") ";
- if (isset($GLOBALS['_OPTIONS']['CREATE_DOC']['group_sn']) ) {
-
- $query = "SELECT dls.ref_doc_line, dls.numero_serie, dls.sn_qte
- FROM docs_lines_sn dls
- WHERE dls.ref_doc_line IN (".$contenu_liste.") ";
-
- }
- $resultat = $bdd->query ($query);
- $numeros = array();
- while ($sn = $resultat->fetchObject()) {
- $numeros[] = $sn;
- }
- // Association des numéros de série au contenu
- for ($i=0; $i<count($this->contenu_materiel); $i++) {
- // Création du tableau de numéros de série
- if ($this->contenu_materiel[$i]->gestion_sn) { $this->contenu_materiel[$i]->sn = array(); }
- // Remplissage du tableau
- foreach ($numeros as $sn) {
- if ($this->contenu_materiel[$i]->ref_doc_line != $sn->ref_doc_line) { continue; }
- $this->contenu_materiel[$i]->sn[] = $sn;
- }
- }
- return true;
- }
- // Chargement du contenu "service_abo" du document
- public function charger_contenu_service_abo () {
- global $bdd;
- global $GESTION_SN;
- $query_infos_supp = $this->doc_line_infos_supp ();
- // *****************************************
- // Chargement du contenu
- $this->contenu_service_abo = array();
- $query = "SELECT dl.ref_doc_line, dl.ref_article, dl.qte, dl.pa_ht, dl.pa_forced, a.gestion_sn
- ".$query_infos_supp['select']."
- FROM docs_lines dl
- LEFT JOIN articles a ON dl.ref_article = a.ref_article
- LEFT JOIN art_categs ac ON a.ref_art_categ = ac.ref_art_categ
- ".$query_infos_supp['left_join']."
- WHERE ref_doc = '".$this->ref_doc."' && a.modele = 'service_abo' && a.lot != '2'";
- $resultat = $bdd->query ($query);
- while ($doc_line = $resultat->fetchObject()) {
- $this->contenu_service_abo[] = $doc_line;
- }
- $this->contenu_service_abo_loaded = true;
- return true;
- }
- // Chargement du contenu "service_conso" du document
- public function charger_contenu_service_conso () {
- global $bdd;
- global $GESTION_SN;
- $query_infos_supp = $this->doc_line_infos_supp ();
- // *****************************************
- // Chargement du contenu
- $this->contenu_service_conso = array();
- $query = "SELECT dl.ref_doc_line, dl.ref_article, dl.qte, dl.pa_ht, dl.pa_forced, a.gestion_sn
- ".$query_infos_supp['select']."
- FROM docs_lines dl
- LEFT JOIN articles a ON dl.ref_article = a.ref_article
- LEFT JOIN art_categs ac ON a.ref_art_categ = ac.ref_art_categ
- ".$query_infos_supp['left_join']."
- WHERE ref_doc = '".$this->ref_doc."' && a.modele = 'service_conso' && a.lot != '2'";
- $resultat = $bdd->query ($query);
- while ($doc_line = $resultat->fetchObject()) {
- $this->contenu_service_conso[] = $doc_line;
- }
- $this->contenu_service_conso_loaded = true;
- return true;
- }
- // Défini les informations supplémentaires a charger avec une ligne de document
- protected function doc_line_infos_supp () {
- $query['select'] = "";
- $query['left_join'] = "";
- return $query;
- }
- // Chargement des informations supplémentaires concernant les numéros de série
- protected function doc_line_sn_infos_supp () {
- $query['select'] = "";
- $query['left_join'] = "";
- return $query;
- }
- // Supprime une ligne de contenu
- public function delete_line ($ref_doc_line) {
- global $bdd;
-
- // On récupère l'article de la ligne
- $query = "SELECT ref_article FROM docs_lines WHERE ref_doc_line = '".$ref_doc_line."';";
- $res = $bdd->query($query);
- if($enr = $res->fetchObject()){
- $article = new article($enr->ref_article);
- // On supprime les lignes de taxes
- $taxes = $article->getTaxes();
- foreach ($taxes as $taxe) {
- $query = "DELETE FROM docs_lines
- WHERE ref_article = 'TAXE " . $taxe->code_taxe . "'
- AND ref_doc_line_parent = '" . $ref_doc_line . "';";
- $bdd->exec($query);
- }
- }
-
- $query = "DELETE FROM docs_lines WHERE ref_doc_line = '".$ref_doc_line."' ";
- $bdd->exec ($query);
- return true;
- }
- // Supprime toutes les lignes de contenu
- public function delete_all_line () {
- global $bdd;
- $query = "DELETE FROM docs_lines WHERE ref_doc = '".$this->ref_doc."' ";
- $bdd->exec ($query);
- return true;
- }
- // *************************************************************************************************************
- // FONCTIONS D'AJOUT DU CONTENU
- // *************************************************************************************************************
- // Ajout d'une ligne au document
- public function add_line ($infos) {
- switch($infos['type_of_line']) {
- case "article" :
- return $this->add_line_article ($infos);
- break;
- case "information":
- return $this->add_line_info ($infos);
- break;
- case "soustotal":
- return $this->add_line_ss_total ($infos);
- break;
- case "taxe":
- return $this->add_line_taxe ($infos);
- break;
- }
- }
- // Ajout d'un article depuis le catalogue
- protected function add_line_article ($infos) {
- global $bdd;
- global $GESTION_SN;
- global $DOC_LINE_ID_REFERENCE_TAG;
- global $ASSUJETTI_TVA;
- global $DEVIS_CLIENT_ID_TYPE_DOC;
- global $COMMANDE_CLIENT_ID_TYPE_DOC;
- global $LIVRAISON_CLIENT_ID_TYPE_DOC;
- global $FACTURE_FOURNISSEUR_ID_TYPE_DOC;
- global $INVENTAIRE_ID_TYPE_DOC;
- global $DEFAUT_ID_PAYS;
-
- // *************************************************
- // Sélection des informations sur l'article
- $ref_article = $infos['ref_article'];
- $article = new article ($ref_article);
- // *************************************************
- // Verification
- if (!$article->getRef_article()) {
- return false;
- }
- $qte = $infos['qte'];
-
- // Si on est sur un inventaire, on n'affiche pas les compositions internes
- if($article->getLot() == 2 && $this->ID_TYPE_DOC == $INVENTAIRE_ID_TYPE_DOC){
- return false;
- }
- // *************************************************
- // Réception des autres variables
- if (isset($infos['pu_ht'])) { $pu_ht = $infos['pu_ht']; }
- else { $pu_ht = $this->select_article_pu ($article, $qte); }
- if (isset($infos['pa_ht']) && !empty($infos['pa_forced'])) {
- $pa_ht = $infos['pa_ht'];
- }
- else {
- $pa_ht = $article->getPaa_ht();
- }
- if (isset($infos['remise'])) {
- $remise = floatval($infos['remise']); }
- else {
- if(!$res =$this->select_infos_article_pcotation($article, $qte))
- $remise = 0;
- else
- $remise = floatval($res->remise);
- }
- if (isset($infos['ref_doc_line_parent'])) { $ref_doc_line_parent = $infos['ref_doc_line_parent']; }
- else { $ref_doc_line_parent = ""; }
- $visible = 1;
- if ($ref_doc_line_parent || (isset($infos['visible']) && $infos['visible'])) { $visible = 0; }
- // *************************************************
- // Création de la référence et de l'ordre
- $ref_doc_line = $this->create_ref_doc_line ();
- $ordre = $this->new_line_order ($ref_doc_line_parent);
-
- //gestion du taux de tva
- if(isset($infos['tva']) && is_numeric($infos['tva'])){
- $article_taux_tva = $infos['tva'];
- }else{
- $article_taux_tva = $article->getTva();
- if (!$ASSUJETTI_TVA && ($this->ID_TYPE_DOC == $DEVIS_CLIENT_ID_TYPE_DOC || $this->ID_TYPE_DOC == $COMMANDE_CLIENT_ID_TYPE_DOC || $this->ID_TYPE_DOC == $LIVRAISON_CLIENT_ID_TYPE_DOC || $this->ID_TYPE_DOC == $FACTURE_FOURNISSEUR_ID_TYPE_DOC)) {$article_taux_tva = 0;}
-
- //mise à zéro du taux de tva si pays client != pays defaut (GESTION TVA INTERNATTIONNAL)
- if (isset($this->id_pays_contact)) {
- if ( $this->id_pays_contact != $DEFAUT_ID_PAYS) {
- $article_taux_tva = 0;…
Large files files are truncated, but you can click here to view the full file