2
0
forked from Wavyzz/dolibarr

Add: Product remaining to be delivered

Fix: move deprecated function
This commit is contained in:
Regis Houssin
2010-01-15 10:07:20 +00:00
parent 81b0fd7f8f
commit 3d3923a22f
8 changed files with 220 additions and 71 deletions

View File

@@ -974,7 +974,8 @@ class Commande extends CommonObject
$this->facturee = $obj->facturee; $this->facturee = $obj->facturee;
$this->note = $obj->note; $this->note = $obj->note;
$this->note_public = $obj->note_public; $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->modelpdf = $obj->model_pdf;
$this->mode_reglement_id = $obj->fk_mode_reglement; $this->mode_reglement_id = $obj->fk_mode_reglement;
$this->mode_reglement_code = $obj->mode_reglement_code; $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 = $obj->cond_reglement_libelle;
$this->cond_reglement_facture = $obj->cond_reglement_libelle_facture; $this->cond_reglement_facture = $obj->cond_reglement_libelle_facture;
$this->date_livraison = $obj->date_livraison; $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->fk_delivery_address = $obj->fk_adresse_livraison;
$this->propale_id = $obj->fk_source; $this->propale_id = $obj->fk_source;
$this->lignes = array(); $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 * \brief Load array this->expeditions of nb of products sent by line in order
* \param filtre_statut Filter on status * \param filtre_statut Filter on status
* \return int <0 if KO, Nb of lines found if OK * \return int <0 if KO, Nb of lines found if OK
* \TODO deprecated, move to Sending class
*/ */
function loadExpeditions($filtre_statut=-1) function loadExpeditions($filtre_statut=-1)
{ {
@@ -1250,7 +1252,7 @@ class Commande extends CommonObject
/** /**
* Renvoie un tableau avec nombre de lignes d'expeditions * Renvoie un tableau avec nombre de lignes d'expeditions
* * \TODO deprecated, move to Sending class
*/ */
function nb_expedition() function nb_expedition()
{ {
@@ -1269,31 +1271,15 @@ class Commande extends CommonObject
* \brief Renvoie un tableau avec les livraisons par ligne * \brief Renvoie un tableau avec les livraisons par ligne
* \param filtre_statut Filtre sur statut * \param filtre_statut Filtre sur statut
* \return int 0 si OK, <0 si KO * \return int 0 si OK, <0 si KO
* \TODO deprecated, move to Delivery class
*/ */
function livraison_array($filtre_statut=-1) function livraison_array($filtre_statut=-1)
{ {
$this->livraisons = array(); $delivery = new Livraison($this->db);
$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'; $deliveryArray = $delivery->livraison_array($filtre_statut);
$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; return $deliveryArray;
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;
} }
/** /**

View File

@@ -358,49 +358,68 @@ class pdf_typhon extends ModelePDFDeliveryOrder
$this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs); $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
$bottomlasttab=$tab_top_newpage + $tab_height_newpage + 1; $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;$i<count($header);$i++)
$pdf->Cell($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 * Pied de page
*/ */
$this->_pagefoot($pdf,$object,$outputlangs); $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;$i<count($header);$i++)
{
$pdf->Cell($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;$i<count($header);$i++)
{
$pdf->Cell($w[$i],7,$header[$i],1,0,'C');
}
$pdf->Ln();
}
}
$this->_pagefoot($pdf,$object,$outputlangs);
}
$pdf->AliasNbPages(); $pdf->AliasNbPages();
$pdf->Close(); $pdf->Close();

View File

@@ -206,6 +206,8 @@ function dol_loginfunction($langs,$conf,$mysoc)
if ($conf->global->MAIN_SMARTY) if ($conf->global->MAIN_SMARTY)
{ {
global $smarty; global $smarty;
$smarty->template_dir=$template_dir;
$smarty->assign('conf_css', $conf_css); $smarty->assign('conf_css', $conf_css);
$smarty->assign('langs', $langs); $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('character_set_client',$conf->file->character_set_client);
$smarty->assign('theme', 'default'); $smarty->assign('theme', 'default');
$smarty->template_dir=$template_dir;
$smarty->assign('dol_url_root', DOL_URL_ROOT); $smarty->assign('dol_url_root', DOL_URL_ROOT);
$smarty->assign('focus_element', $focus_element); $smarty->assign('focus_element', $focus_element);

View File

@@ -254,7 +254,7 @@ if ($_GET["action"] == 'create')
$lignes = $commande->fetch_lines(1); $lignes = $commande->fetch_lines(1);
/* Lecture des livraisons d<EFBFBD>j<EFBFBD> effectu<EFBFBD>es */ /* Lecture des livraisons deje effectuees */
$commande->livraison_array(); $commande->livraison_array();
$num = sizeof($commande->lignes); $num = sizeof($commande->lignes);

View File

@@ -780,14 +780,130 @@ class Livraison extends CommonObject
$ligne->total_ht = 100; $ligne->total_ht = 100;
$this->lignes[$i] = $ligne; $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 * \class LivraisonLigne
\brief Classe de gestion des lignes de bons de livraison * \brief Classe de gestion des lignes de bons de livraison
*/ */
class LivraisonLigne class LivraisonLigne
{ {

View File

@@ -25,8 +25,9 @@
*/ */
require("../main.inc.php"); require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
require_once(DOL_DOCUMENT_ROOT."/livraison/livraison.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("orders");
$langs->load("sendings"); $langs->load("sendings");

View File

@@ -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 * Phase authentication / login

View File

@@ -177,16 +177,16 @@ class Project extends CommonObject
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ref = $obj->ref; $this->ref = $obj->ref;
$this->title = $obj->title; $this->title = $obj->title;
$this->titre = $obj->title; $this->titre = $obj->title; // TODO deprecated
$this->date_c = $this->db->jdate($obj->datec); $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->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_start = $this->db->jdate($obj->dateo);
$this->date_end = $this->db->jdate($obj->datee); $this->date_end = $this->db->jdate($obj->datee);
$this->note = $obj->note; $this->note = $obj->note;
$this->socid = $obj->fk_soc; $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_author_id = $obj->fk_user_creat;
$this->user_resp_id = $obj->fk_user_resp; $this->user_resp_id = $obj->fk_user_resp;
$this->statut = $obj->fk_statut; $this->statut = $obj->fk_statut;