diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 07d20490615..8bd76831d12 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -974,7 +974,8 @@ class Commande extends CommonObject $this->facturee = $obj->facturee; $this->note = $obj->note; $this->note_public = $obj->note_public; - $this->projet_id = $obj->fk_projet; + $this->projet_id = $obj->fk_projet; // TODO deprecated + $this->fk_project = $obj->fk_projet; $this->modelpdf = $obj->model_pdf; $this->mode_reglement_id = $obj->fk_mode_reglement; $this->mode_reglement_code = $obj->mode_reglement_code; @@ -984,7 +985,7 @@ class Commande extends CommonObject $this->cond_reglement = $obj->cond_reglement_libelle; $this->cond_reglement_facture = $obj->cond_reglement_libelle_facture; $this->date_livraison = $obj->date_livraison; - $this->adresse_livraison_id = $obj->fk_adresse_livraison; // TODO obsolete + $this->adresse_livraison_id = $obj->fk_adresse_livraison; // TODO deprecated $this->fk_delivery_address = $obj->fk_adresse_livraison; $this->propale_id = $obj->fk_source; $this->lignes = array(); @@ -1205,6 +1206,7 @@ class Commande extends CommonObject * \brief Load array this->expeditions of nb of products sent by line in order * \param filtre_statut Filter on status * \return int <0 if KO, Nb of lines found if OK + * \TODO deprecated, move to Sending class */ function loadExpeditions($filtre_statut=-1) { @@ -1250,7 +1252,7 @@ class Commande extends CommonObject /** * Renvoie un tableau avec nombre de lignes d'expeditions - * + * \TODO deprecated, move to Sending class */ function nb_expedition() { @@ -1269,31 +1271,15 @@ class Commande extends CommonObject * \brief Renvoie un tableau avec les livraisons par ligne * \param filtre_statut Filtre sur statut * \return int 0 si OK, <0 si KO + * \TODO deprecated, move to Delivery class */ function livraison_array($filtre_statut=-1) { - $this->livraisons = array(); - $sql = 'SELECT cd.fk_product, sum(ed.qty)'; - $sql.=' FROM '.MAIN_DB_PREFIX.'livraisondet as ld, '.MAIN_DB_PREFIX.'livraison as l, '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'commandedet as cd'; - $sql.=' WHERE ld.fk_livraison = l.rowid AND ld.fk_commande_ligne = cd .rowid AND cd.fk_commande = c.rowid'; - $sql.=' AND cd.fk_commande =' .$this->id; - if ($filtre_statut >= 0) $sql.=' AND l.fk_statut = '.$filtre_statut; - $sql .= ' GROUP BY cd.fk_product '; - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($resql); - $this->livraisons[$row[0]] = $row[1]; - $i++; - } - $this->db->free(); - } - - return 0; + $delivery = new Livraison($this->db); + + $deliveryArray = $delivery->livraison_array($filtre_statut); + + return $deliveryArray; } /** diff --git a/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php b/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php index 6f4b3ff65f7..baad4967f5d 100644 --- a/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php +++ b/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php @@ -358,49 +358,68 @@ class pdf_typhon extends ModelePDFDeliveryOrder $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs); $bottomlasttab=$tab_top_newpage + $tab_height_newpage + 1; } - - $requeteTest = "SELECT ref, label, co.qty-li.qty"; - $requeteTest = $requeteTest." FROM llx_commandedet AS co"; - //$requeteTest = $requeteTest." INNER JOIN llx_element_element AS el ON co.fk_commande = el.fk_source"; - $requeteTest = $requeteTest." INNER JOIN llx_livraisondet AS li"; - $requeteTest = $requeteTest." ON li.fk_origin_line = co.rowid"; - $requeteTest = $requeteTest." INNER JOIN llx_product AS pr"; - $requeteTest = $requeteTest." ON pr.rowid = li.fk_product"; - $requeteTest = $requeteTest." WHERE fk_livraison =".$object->id; - - $resultaTest = $this->db->query($requeteTest); - - if ($this->db->num_rows($resultaTest)) { - - $pdf->SetTextColor(0,0,0); - $pdf->SetFont('Arial','',9); - $pdf->SetY(-65); - - $w=array(40,100,50); - $header=array('Reference','Libelle','Quantite'); - - //En-tête - for($i=0;$iCell($w[$i],7,$header[$i],1,0,'C'); - $pdf->Ln(); - - //Données - while($ligneTest = $this->db->fetch_array($resultaTest)) - { - if ($ligneTest[2] > 0) - { - $pdf->Cell($w[0], 6, $ligneTest[0], 1, 0, 'L'); - $pdf->Cell($w[1], 6, $ligneTest[1], 1, 0, 'L'); - $pdf->Cell($w[2], 6, $ligneTest[2], 1, 1, 'R'); - } - } - } /* * Pied de page */ $this->_pagefoot($pdf,$object,$outputlangs); + + // Check product remaining to be delivered + $waitingDelivery = $object->getRemainingDelivered(); + + if (is_array($waitingDelivery) & !empty($waitingDelivery)) + { + $pdf->AddPage('P', 'A4'); + + $this->_pagehead($pdf, $object, 1, $outputlangs); + $pdf-> SetY(90); + + $w=array(40,100,50); + $header=array($outputlangs->transnoentities('Reference'), + $outputlangs->transnoentities('Label'), + $outputlangs->transnoentities('Qty') + ); + + // Header + for($i=0;$iCell($w[$i],7,$header[$i],1,0,'C'); + } + + $pdf->Ln(); + + // Data + foreach($waitingDelivery as $value) + { + $pdf->Cell($w[0], 6, $value['ref'], 1, 0, 'L'); + $pdf->Cell($w[1], 6, $value['label'], 1, 0, 'L'); + $pdf->Cell($w[2], 6, $value['qty'], 1, 1, 'R'); + + if ($pdf->GetY() > 250) + { + $this->_pagefoot($pdf,$object,$outputlangs); + + $pdf->AddPage('P', 'A4'); + + $pdf->SetFont('Arial','', 9); + $this->_pagehead($pdf, $object, 0, $outputlangs); + + $pdf-> SetY(40); + + for($i=0;$iCell($w[$i],7,$header[$i],1,0,'C'); + } + + $pdf->Ln(); + } + } + + $this->_pagefoot($pdf,$object,$outputlangs); + + } + $pdf->AliasNbPages(); $pdf->Close(); diff --git a/htdocs/lib/security.lib.php b/htdocs/lib/security.lib.php index 5af17070eaa..fcf4ad8cbca 100644 --- a/htdocs/lib/security.lib.php +++ b/htdocs/lib/security.lib.php @@ -206,6 +206,8 @@ function dol_loginfunction($langs,$conf,$mysoc) if ($conf->global->MAIN_SMARTY) { global $smarty; + + $smarty->template_dir=$template_dir; $smarty->assign('conf_css', $conf_css); $smarty->assign('langs', $langs); @@ -216,7 +218,7 @@ function dol_loginfunction($langs,$conf,$mysoc) $smarty->assign('character_set_client',$conf->file->character_set_client); $smarty->assign('theme', 'default'); - $smarty->template_dir=$template_dir; + $smarty->assign('dol_url_root', DOL_URL_ROOT); $smarty->assign('focus_element', $focus_element); diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index 57ba7160ca9..509024d46df 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -254,7 +254,7 @@ if ($_GET["action"] == 'create') $lignes = $commande->fetch_lines(1); - /* Lecture des livraisons d�j� effectu�es */ + /* Lecture des livraisons deje effectuees */ $commande->livraison_array(); $num = sizeof($commande->lignes); diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index 8b446587ec7..1f219b609b6 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -780,14 +780,130 @@ class Livraison extends CommonObject $ligne->total_ht = 100; $this->lignes[$i] = $ligne; } + + /** + * \brief Renvoie la quantite de produit restante a livrer pour une commande + * \return array Product remaining to be delivered + */ + function getRemainingDelivered() + { + // Get the source id and source type + $sqlSource = "SELECT fk_source, sourcetype"; + $sqlSource.= " FROM ".MAIN_DB_PREFIX."element_element"; + $sqlSource.= " WHERE fk_target = ".$this->id; + $sqlSource.= " AND targettype = '".$this->element."'"; + + $resultSource = $this->db->query($sqlSource); + $objSource = $this->db->fetch_object($resultSource); + + // Get the product ref and qty in source + $sqlSourceLine = "SELECT p.ref, p.label, st.rowid, st.qty"; + $sqlSourceLine.= " FROM ".MAIN_DB_PREFIX.$objSource->sourcetype."det as st"; + $sqlSourceLine.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON st.fk_product = p.rowid"; + $sqlSourceLine.= " WHERE fk_".$objSource->sourcetype." = ".$objSource->fk_source; + + $resultSourceLine = $this->db->query($sqlSourceLine); + if ($resultSourceLine) + { + $num_lines = $this->db->num_rows($resultSourceLine); + $i = 0; + $resultArray = array(); + while ($i < $num_lines) + { + $objSourceLine = $this->db->fetch_object($resultSourceLine); + + // Recupere les lignes de la source deja livrees + $sql3 = "SELECT ld.fk_origin_line, sum(ld.qty) as qty"; + $sql3 .= " FROM ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l,"; + $sql3 .= " ".MAIN_DB_PREFIX.$objSource->sourcetype." as c, ".MAIN_DB_PREFIX.$objSource->sourcetype."det as cd"; + $sql3 .= " WHERE ld.fk_livraison = l.rowid AND ld.fk_origin_line = cd.rowid"; + $sql3 .= " AND cd.fk_".$objSource->sourcetype." = c.rowid"; + $sql3 .= " AND cd.fk_".$objSource->sourcetype." = ".$objSource->fk_source; + $sql3 .= " AND ld.fk_origin_line = ".$objSourceLine->rowid; + $sql3 .= " GROUP BY ld.fk_origin_line"; + + $result = $this->db->query($sql3); + $row = $this->db->fetch_row($result); + + if ($obj->qty - $row[1] > 0) + { + if ($row[0] == $obj->rowid) + { + $array[$i]['qty'] = $obj->qty - $row[1]; + } + else + { + $array[$i]['qty'] = $obj->qty; + } + + $array[$i]['ref'] = $obj->ref; + $array[$i]['label'] = $obj->label; + } + elseif($obj->qty - $row[1] < 0) + { + $array[$i]['qty'] = $obj->qty - $row[1]. " Erreur livraison !"; + $array[$i]['ref'] = $obj->ref; + $array[$i]['label'] = $obj->label; + } + + $i++; + } + return $array; + } + else + { + $this->error=$this->db->error()." - sql=$sql"; + dol_syslog("livraison.class.php::getRemainingDelivered ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * \brief Renvoie un tableau avec les livraisons par ligne + * \param filtre_statut Filtre sur statut + * \return int 0 si OK, <0 si KO + * \TODO obsolete + */ + function livraison_array($filtre_statut=-1) + { + $this->livraisons = array(); + + $sql = 'SELECT cd.fk_product, SUM(ld.qty)'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'livraisondet as ld'; + $sql.= ', '.MAIN_DB_PREFIX.'livraison as l'; + $sql.= ', '.MAIN_DB_PREFIX.'commande as c'; + $sql.= ', '.MAIN_DB_PREFIX.'commandedet as cd'; + $sql.= ' WHERE ld.fk_livraison = l.rowid'; + $sql.= ' AND ld.fk_commande_ligne = cd .rowid'; + $sql.= ' AND cd.fk_commande = c.rowid'; + $sql.= ' AND cd.fk_commande =' .$this->id; + if ($filtre_statut >= 0) $sql.=' AND l.fk_statut = '.$filtre_statut; + $sql.= ' GROUP BY cd.fk_product '; + + $resql = $this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + $this->livraisons[$row[0]] = $row[1]; + $i++; + } + $this->db->free(); + } + + return 0; + } } /** - \class LivraisonLigne - \brief Classe de gestion des lignes de bons de livraison + * \class LivraisonLigne + * \brief Classe de gestion des lignes de bons de livraison */ class LivraisonLigne { diff --git a/htdocs/livraison/pre.inc.php b/htdocs/livraison/pre.inc.php index 7bb80186502..ff1816e3ba0 100644 --- a/htdocs/livraison/pre.inc.php +++ b/htdocs/livraison/pre.inc.php @@ -25,8 +25,9 @@ */ require("../main.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); require_once(DOL_DOCUMENT_ROOT."/livraison/livraison.class.php"); +if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); +if ($conf->propale->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); $langs->load("orders"); $langs->load("sendings"); diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 069a6d9814a..b9a06c7acaf 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -248,6 +248,31 @@ if (sizeof($conf->need_smarty) > 0 || $conf->global->MAIN_SMARTY) } } +// Init Dwoo +if ($conf->global->MAIN_DWOO2) +{ + // Usage of const in conf.php file can overwrite default dir. + if (empty($dolibarr_dwoo_libs_dir)) $dolibarr_dwoo_libs_dir=DOL_DOCUMENT_ROOT.'/includes/dwoo/'; + if (empty($dolibarr_dwoo_compile)) $dolibarr_dwoo_compile=DOL_DATA_ROOT.'/dwoo/templates/temp'; + if (empty($dolibarr_dwoo_cache)) $dolibarr_dwoo_cache=DOL_DATA_ROOT.'/dwoo/cache/temp'; + + //$dwoo_libs = $dolibarr_dwoo_libs_dir. "dwooAutoload.php"; + $dwoo_libs = $dolibarr_dwoo_libs_dir. "Dwoo.php"; + $dwoo_smarty_adapter = $dolibarr_dwoo_libs_dir. "Dwoo/Smarty/Adapter.php"; + + if (include_once($dwoo_libs) && include_once($dwoo_smarty_adapter)) + { + //$dwoo = new Dwoo($dolibarr_dwoo_compile,$dolibarr_dwoo_cache); + $smarty = new Dwoo_Smarty_Adapter(); + $smarty->show_compat_errors = true; + $smarty->compile_dir = $dolibarr_smarty_compile; + $smarty->cache_dir = $dolibarr_smarty_cache; + } + else + { + dol_print_error('',"Library Dwoo ".$dwoo_libs." not found."); + } +} /* * Phase authentication / login diff --git a/htdocs/project.class.php b/htdocs/project.class.php index e3711e9a7f7..72e32fbf9b3 100644 --- a/htdocs/project.class.php +++ b/htdocs/project.class.php @@ -177,16 +177,16 @@ class Project extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->ref; $this->title = $obj->title; - $this->titre = $obj->title; + $this->titre = $obj->title; // TODO deprecated $this->date_c = $this->db->jdate($obj->datec); - $this->datec = $this->db->jdate($obj->datec); // deprecated + $this->datec = $this->db->jdate($obj->datec); // TODO deprecated $this->date_m = $this->db->jdate($obj->tms); - $this->datem = $this->db->jdate($obj->tms); // deprecated + $this->datem = $this->db->jdate($obj->tms); // TODO deprecated $this->date_start = $this->db->jdate($obj->dateo); $this->date_end = $this->db->jdate($obj->datee); $this->note = $obj->note; $this->socid = $obj->fk_soc; - $this->societe->id = $obj->fk_soc; // For backward compatibility + $this->societe->id = $obj->fk_soc; // TODO For backward compatibility $this->user_author_id = $obj->fk_user_creat; $this->user_resp_id = $obj->fk_user_resp; $this->statut = $obj->fk_statut;