From 9dbcea96b98ab8dd74bbcc5e3852f39ad43094d8 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 31 Jan 2008 14:23:57 +0000 Subject: [PATCH] =?UTF-8?q?D=E9but=20modification=20expedition=20livraison?= =?UTF-8?q?=20Phase2:=20modification=20des=20livraisons=20-=20elles=20pour?= =?UTF-8?q?ront=20d=E9sormais=20etre=20li=E9=20=E0=20une=20propale=20(pas?= =?UTF-8?q?=20encore=20effectif)=20-=20on=20pourra=20faire=20un=20bon=20de?= =?UTF-8?q?=20livraison=20sans=20document=20de=20base?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/livraison/fiche.php | 529 +++++++++++++-------------- htdocs/livraison/livraison.class.php | 88 +++-- 2 files changed, 318 insertions(+), 299 deletions(-) diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index 6c8b424c308..5f0172e9b3d 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -356,296 +356,285 @@ else /* Mode vue et edition */ /* */ /* *************************************************************************** */ -{ - if ($_GET["id"] > 0) +{ + if ($_GET["id"] > 0) + { + $livraison = new Livraison($db); + $result = $livraison->fetch($_GET["id"]); + + if ( $livraison->id > 0) { - $livraison = new Livraison($db); - $result = $livraison->fetch($_GET["id"]); + $soc = new Societe($db); + $soc->fetch($livraison->socid); + + $h=0; + if ($conf->expedition_bon->enabled) + { + $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$livraison->expedition_id; + $head[$h][1] = $langs->trans("SendingCard"); + $h++; + } + + $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$livraison->id; + $head[$h][1] = $langs->trans("DeliveryCard"); + $hselected = $h; + $h++; + + dolibarr_fiche_head($head, $hselected, $langs->trans("Sending")); - if ( $livraison->id > 0) + /* + * Confirmation de la suppression + * + */ + if ($_GET["action"] == 'delete') + { + $expedition_id = $_GET["expid"]; + $html->form_confirm("fiche.php?id=$livraison->id&expid=$expedition_id","Supprimer le bon de livraison","Etes-vous sûr de vouloir supprimer ce bon de livraison ?","confirm_delete"); + print '
'; + } + + /* + * Confirmation de la validation + * + */ + if ($_GET["action"] == 'valid') + { + $html->form_confirm("fiche.php?id=$livraison->id","Valider le bon de livraison","Etes-vous sûr de vouloir valider ce bon de livraison ?","confirm_valid"); + print '
'; + } + + + /* + * Livraison + */ + print ''; + + // Ref + print ''; + print ''; + + // Client + print ''; + print ''; + print ""; + + // Document origine + print ''; + print '\n"; + print ''; + + // Commande liée + print ''; + print '\n"; + print ''; + + // Date + print ''; + print '\n"; + print ''; + + // Statut + print ''; + print '\n"; + print ''; + + if (!$conf->expedition_bon->enabled && $conf->stock->enabled) + { + // Entrepot + $entrepot = new Entrepot($db); + $entrepot->fetch($livraison->entrepot_id); + print ''; + print ''; + print ''; + } + + print "
'.$langs->trans("Ref").''.$livraison->ref.'
'.$langs->trans("Customer").''.$soc->getNomUrl(1).'
'.$langs->trans("RefOrder").''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref."
'.$langs->trans("RefCustomerOrderShort").''.$livraison->ref_client."
'.$langs->trans("Date").''.dolibarr_print_date($livraison->date_creation,'dayhourtext')."
'.$langs->trans("Status").''.$livraison->getLibStatut(4)."
'.$langs->trans("Warehouse").''.$entrepot->libelle.'
\n"; + + /* + * Lignes produits + */ + print '
'; + + $num_prod = sizeof($livraison->lignes); + + if ($num_prod) + { + $i = 0; + + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $var=true; + while ($i < $num_prod) { - - $commande = New Commande($db); - $commande->fetch($livraison->commande_id); - - $soc = new Societe($db); - $soc->fetch($commande->socid); - - $h=0; - if ($conf->expedition_bon->enabled) - { - $head[$h][0] = DOL_URL_ROOT."/expedition/fiche.php?id=".$livraison->expedition_id; - $head[$h][1] = $langs->trans("SendingCard"); - $h++; - } - - $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$livraison->id; - $head[$h][1] = $langs->trans("DeliveryCard"); - $hselected = $h; - $h++; - - dolibarr_fiche_head($head, $hselected, $langs->trans("Sending")); - - /* - * Confirmation de la suppression - * - */ - if ($_GET["action"] == 'delete') - { - $expedition_id = $_GET["expid"]; - $html->form_confirm("fiche.php?id=$livraison->id&expid=$expedition_id","Supprimer le bon de livraison","Etes-vous sûr de vouloir supprimer ce bon de livraison ?","confirm_delete"); - print '
'; - } - - /* - * Confirmation de la validation - * - */ - if ($_GET["action"] == 'valid') - { - $html->form_confirm("fiche.php?id=$livraison->id","Valider le bon de livraison","Etes-vous sûr de vouloir valider ce bon de livraison ?","confirm_valid"); - print '
'; - } - - - /* - * Commande - */ - if ($commande->brouillon == 1 && $user->rights->commande->creer) - { - print ''; - } - - print '
'.$langs->trans("Products").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyReceived").'
'; - - // Ref - print ''; - print ''; - - // Client - print ''; - print ''; - print ""; - - // Commande liée - print ''; - print '\n"; - print ''; - - // Commande liée - print ''; - print '\n"; - print ''; - - // Date - print ''; - print '\n"; - print ''; - - // Statut - print ''; - print '\n"; - print ''; - - if (!$conf->expedition_bon->enabled && $conf->stock->enabled) - { - // Entrepot - $entrepot = new Entrepot($db); - $entrepot->fetch($livraison->entrepot_id); - print ''; - print ''; - print ''; - } - - print "
'.$langs->trans("Ref").''.$livraison->ref.'
'.$langs->trans("Customer").''.$soc->getNomUrl(1).'
'.$langs->trans("RefOrder").''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref."
'.$langs->trans("RefCustomerOrderShort").''.$commande->ref_client."
'.$langs->trans("Date").''.dolibarr_print_date($livraison->date_creation,'dayhourtext')."
'.$langs->trans("Status").''.$livraison->getLibStatut(4)."
'.$langs->trans("Warehouse").''.$entrepot->libelle.'
\n"; - - /* - * Lignes produits - */ - print '
'; - - $num_prod = sizeof($livraison->lignes); - - if ($num_prod) - { - $i = 0; - - print ''; - print ''; - print ''; - print ''; - print "\n"; - - $var=true; - while ($i < $num_prod) - { - $var=!$var; - print ""; - if ($livraison->lignes[$i]->fk_product > 0) - { - $product = new Product($db); - $product->fetch($livraison->lignes[$i]->fk_product); + $var=!$var; + print ""; + if ($livraison->lignes[$i]->fk_product > 0) + { + $product = new Product($db); + $product->fetch($livraison->lignes[$i]->fk_product); - print ''; - } - else - { - print "\n"; - } - print ''; - print ''; + print ''; + } + else + { + print "\n"; + } + + print ''; + print ''; - print ""; + print ""; - $i++; - } - } + $i++; + } + } + + print "
'.$langs->trans("Products").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyReceived").'
'; - print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; - if ($livraison->lignes[$i]->description) print '
'.$livraison->lignes[$i]->description; - print '
".$livraison->lignes[$i]->description."'.$livraison->lignes[$i]->qty_asked.''.$livraison->lignes[$i]->qty_delivered.''; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; + if ($livraison->lignes[$i]->description) print '
'.$livraison->lignes[$i]->description; + print '
".$livraison->lignes[$i]->description."'.$livraison->lignes[$i]->qty_asked.''.$livraison->lignes[$i]->qty_delivered.'
\n"; - print "\n"; - - print "\n\n"; + print "\n\n"; - /* - * Boutons actions - */ + /* + * Boutons actions + */ - if ($user->societe_id == 0) - { - print '
'; - - if (! eregi('^(valid|delete)',$_REQUEST["action"])) - { - if ($livraison->statut == 0 && $user->rights->expedition->livraison->valider && $num_prod > 0) - { - print ''.$langs->trans("Validate").''; - } + if ($user->societe_id == 0) + { + print '
'; + + if (! eregi('^(valid|delete)',$_REQUEST["action"])) + { + if ($livraison->statut == 0 && $user->rights->expedition->livraison->valider && $num_prod > 0) + { + print ''.$langs->trans("Validate").''; + } + + if ($livraison->brouillon && $user->rights->expedition->livraison->supprimer) + { + if ($conf->expedition_bon->enabled) + { + print ''.$langs->trans("Delete").''; + } + else + { + print ''.$langs->trans("Delete").''; + } + } + } + + print '
'; + } + print "\n"; - if ($livraison->brouillon && $user->rights->expedition->livraison->supprimer) - { - if ($conf->expedition_bon->enabled) - { - print ''.$langs->trans("Delete").''; - } - else - { - print ''.$langs->trans("Delete").''; - } - } - } - - print '
'; - } - print "\n"; - - print "
"; - - /* - * Documents générés - */ + print "'; } - else { - dolibarr_print_error($db); + else + { + print "\n"; } - - - print ''; + print ''; + print ''; + $i++; + } + + print '
"; + + /* + * Documents générés + */ - $livraisonref = sanitize_string($livraison->ref); - $filedir = $conf->livraison->dir_output . '/' . $livraisonref; - $urlsource = $_SERVER["PHP_SELF"]."?id=".$livraison->id; + $livraisonref = sanitize_string($livraison->ref); + $filedir = $conf->livraison->dir_output . '/' . $livraisonref; + $urlsource = $_SERVER["PHP_SELF"]."?id=".$livraison->id; - $genallowed=$user->rights->expedition->livraison->creer; - $delallowed=$user->rights->expedition->livraison->supprimer; - //$genallowed=1; - //$delallowed=0; + $genallowed=$user->rights->expedition->livraison->creer; + $delallowed=$user->rights->expedition->livraison->supprimer; + + $somethingshown=$formfile->show_documents('livraison',$livraisonref,$filedir,$urlsource,$genallowed,$delallowed,$livraison->modelpdf); - $somethingshown=$formfile->show_documents('livraison',$livraisonref,$filedir,$urlsource,$genallowed,$delallowed,$livraison->modelpdf); + /* + * Déjà livre + */ + $sql = "SELECT ld.fk_product, ld.description, ld.qty as qty_livre, ld.fk_livraison as livraison_id"; + $sql.= ", l.ref, ".$db->pdate("l.date_livraison")." as date_livraison"; + $sql.= ", cd.rowid, cd.qty as qty_commande"; + $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; + $sql.= " , ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l"; + $sql.= " WHERE cd.fk_commande = ".$livraison->commande_id; + $sql.= " AND l.rowid <> ".$livraison->id; + $sql.= " AND cd.rowid = ld.fk_origin_line"; + $sql.= " AND ld.fk_livraison = l.rowid"; + $sql.= " AND l.fk_statut > 0"; + $sql.= " ORDER BY cd.fk_product"; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + if ($num) + { + print '
'; - /* - * Déjà livre - */ - $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande"; - $sql .= " , ld.qty as qty_livre, l.ref, ld.fk_livraison as livraison_id"; - $sql .= ",".$db->pdate("l.date_livraison")." as date_livraison"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; - $sql .= " , ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l"; - $sql .= " WHERE cd.fk_commande = ".$livraison->commande_id; - $sql .= " AND l.rowid <> ".$livraison->id; - $sql .= " AND cd.rowid = ld.fk_commande_ligne"; - $sql .= " AND ld.fk_livraison = l.rowid"; - $sql .= " AND l.fk_statut > 0"; - $sql .= " ORDER BY cd.fk_product"; - - $resql = $db->query($sql); - if ($resql) + print_titre($langs->trans("OtherSendingsForSameOrder")); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $var=True; + while ($i < $num) + { + $var=!$var; + $objp = $db->fetch_object($resql); + print ""; + print ''; + if ($objp->fk_product > 0) { - $num = $db->num_rows($resql); - $i = 0; - - if ($num) - { - print '
'; - - print_titre($langs->trans("OtherSendingsForSameOrder")); - print '
'.$langs->trans("Sending").''.$langs->trans("Description").''.$langs->trans("QtyShipped").''.$langs->trans("Date").'
'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - $var=True; - while ($i < $num) - { - $var=!$var; - $objp = $db->fetch_object($resql); - print ""; - print ''; - if ($objp->fk_product > 0) - { - $product = new Product($db); - $product->fetch($objp->fk_product); - - print ''; - } - else - { - print "\n"; - } - print ''; - print ''; - print ''; - $i++; - } - - print '
'.$langs->trans("Sending").''.$langs->trans("Description").''.$langs->trans("QtyShipped").''.$langs->trans("Date").'
'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''; - print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; - if ($objp->description) print nl2br($objp->description); - print '".stripslashes(nl2br($objp->description))."'.$objp->qty_livre.''.dolibarr_print_date($objp->date_livraison,"dayhour").'
'; - } - $db->free($resql); + $product = new Product($db); + $product->fetch($objp->fk_product); + + print '
'; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; + if ($objp->description) print nl2br($objp->description); + print '".stripslashes(nl2br($objp->description))."'; + print ''.$objp->qty_livre.''.dolibarr_print_date($objp->date_livraison,"dayhour").'
'; + } + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } + + print '
'; // Rien à droite - - print '
'; - - } - else - { - /* Expedition non trouvée */ - print "Expedition inexistante ou accés refusé"; - } - } - else - { - /* Expedition non trouvée */ - print "Expedition inexistante ou accés refusé"; - } + + print ''; + } + else + { + /* Expedition non trouvée */ + print "Expedition inexistante ou accés refusé"; + } + } + else + { + /* Expedition non trouvée */ + print "Expedition inexistante ou accés refusé"; + } } $db->close(); diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index a4328260140..d8016b91347 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -234,39 +234,69 @@ class Livraison extends CommonObject $sql.= " WHERE l.rowid = ".$id; $result = $this->db->query($sql) ; - if ( $result ) + if ($result) { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - $this->date_creation = $obj->date_creation; - $this->date_valid = $obj->date_valid; - $this->ref = $obj->ref; - $this->ref_client = $obj->ref_client; - $this->socid = $obj->fk_soc; - $this->statut = $obj->fk_statut; - $this->origin_id = $obj->origin_id; - $this->expedition_id = $obj->fk_expedition; - $this->user_author_id = $obj->fk_user_author; - $this->user_valid_id = $obj->fk_user_valid; - $this->date_livraison = $obj->date_livraison; - $this->adresse_livraison_id = $obj->fk_adresse_livraison; - $this->note = $obj->note; - $this->note_public = $obj->note_public; - $this->modelpdf = $obj->model_pdf; - $this->db->free(); - - if ($this->statut == 0) $this->brouillon = 1; - - $file = $conf->livraison->dir_output . "/" .get_exdir($livraison->id,2) . "/" . $this->id.".pdf"; - $this->pdf_filename = $file; - - $this->fetch_lignes(); - - return 1; + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + + $this->id = $obj->rowid; + $this->date_creation = $obj->date_creation; + $this->date_valid = $obj->date_valid; + $this->ref = $obj->ref; + $this->ref_client = $obj->ref_client; + $this->socid = $obj->fk_soc; + $this->statut = $obj->fk_statut; + $this->origin_id = $obj->origin_id; + $this->expedition_id = $obj->fk_expedition; + $this->user_author_id = $obj->fk_user_author; + $this->user_valid_id = $obj->fk_user_valid; + $this->date_livraison = $obj->date_livraison; + $this->adresse_livraison_id = $obj->fk_adresse_livraison; + $this->note = $obj->note; + $this->note_public = $obj->note_public; + $this->modelpdf = $obj->model_pdf; + + $this->db->free($result); + + if ($this->origin_id) + { + if ($conf->commande->enabled) + { + $this->origin = "commande"; + } + else + { + $this->origin = "propal"; + } + } + + if ($this->statut == 0) $this->brouillon = 1; + + $file = $conf->livraison->dir_output . "/" .get_exdir($livraison->id,2) . "/" . $this->id.".pdf"; + $this->pdf_filename = $file; + + /* + * Lignes + */ + $result=$this->fetch_lignes(); + if ($result < 0) + { + return -3; + } + + return 1; + } + else + { + $this->error='Delivery with id '.$rowid.' not found sql='.$sql; + dolibarr_syslog('Livraison::Fetch Error '.$this->error); + return -2; + } } else { + dolibarr_syslog('Livraison::Fetch Error '.$this->error); $this->error=$this->db->error(); return -1; }