* Copyright (C) 2005-2010 Laurent Destailleur * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2013 Florian Henry * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/livraison/card.php * \ingroup livraison * \brief Fiche descriptive d'un bon de livraison=reception */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php'; if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; if (! empty($conf->expedition_bon->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; $langs->load("sendings"); $langs->load("bills"); $langs->load('deliveries'); $langs->load('orders'); if (!empty($conf->incoterm->enabled)) $langs->load('incoterm'); $action=GETPOST('action', 'alpha'); $confirm=GETPOST('confirm', 'alpha'); $backtopage=GETPOST('backtopage'); // Security check $id = GETPOST('id', 'int'); if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'expedition',$id,'livraison','livraison'); $object = new Livraison($db); // Load object if ($id > 0 || ! empty($ref)) { $ret = $object->fetch($id, $ref); if ($ret > 0) $ret = $object->fetch_thirdparty(); if ($ret < 0) dol_print_error('', $object->error); } // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('deliverycard','globalcard')); /* * Actions */ $parameters=array(); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($action == 'add') { $db->begin(); $object->date_livraison = time(); $object->note = $_POST["note"]; $object->commande_id = $_POST["commande_id"]; $object->fk_incoterms = GETPOST('incoterm_id', 'int'); if (!$conf->expedition_bon->enabled && ! empty($conf->stock->enabled)) { $expedition->entrepot_id = $_POST["entrepot_id"]; } // On boucle sur chaque ligne de commande pour completer objet livraison // avec qte a livrer $commande = new Commande($db); $commande->fetch($object->commande_id); $commande->fetch_lines(); $num=count($commande->lines); for ($i = 0; $i < $num; $i++) { $qty = "qtyl".$i; $idl = "idl".$i; if ($_POST[$qty] > 0) { $object->addline($_POST[$idl],$_POST[$qty]); } } $ret=$object->create($user); if ($ret > 0) { $db->commit(); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { setEventMessage($object->error, 'errors'); $db->rollback(); $_GET["commande_id"]=$_POST["commande_id"]; $action='create'; } } else if ($action == 'confirm_valid' && $confirm == 'yes' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison->creer)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison_advance->validate))) ) { $result = $object->valid($user); // Define output language if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records $result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result < 0) dol_print_error($db,$result); } } if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->livraison->supprimer) { $db->begin(); $result=$object->delete(); if ($result > 0) { $db->commit(); if (! empty($backtopage)) header("Location: ".$backtopage); else header("Location: ".DOL_URL_ROOT.'/expedition/index.php'); exit; } else { $db->rollback(); } } if ($action == 'setdate_livraison' && $user->rights->expedition->livraison->creer) { $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int')); $result=$object->set_date_livraison($user,$datedelivery); if ($result < 0) { $mesg='
'.$object->error.'
'; } } // Set incoterm elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) { $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); } /* * Build document */ if ($action == 'builddoc') // En get ou en post { // Save last template used to generate document if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $ret=$object->fetch($id); // Reload to get new records $result= $object->generateDocument($object->modelpdf, $outputlangs); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action=''; } } // Delete file in doc form elseif ($action == 'remove_file') { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->expedition->dir_output . "/receipt"; $file = $upload_dir . '/' . GETPOST('file'); $ret=dol_delete_file($file,0,0,0,$object); if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); } /* * View */ llxHeader('',$langs->trans('Delivery'),'Livraison'); $form = new Form($db); $formfile = new FormFile($db); /********************************************************************* * * Mode creation * *********************************************************************/ if ($action == 'create') { print_fiche_titre($langs->trans("CreateADeliveryOrder")); if ($mesg) { print $mesg.'
'; } $commande = new Commande($db); $commande->livraison_array(); if ($commande->fetch(GETPOST("commande_id"))) { $soc = new Societe($db); $soc->fetch($commande->socid); $author = new User($db); $author->fetch($commande->user_author_id); if (!$conf->expedition_bon->enabled && ! empty($conf->stock->enabled)) { $entrepot = new Entrepot($db); } /* * Commande */ print '
'; print ''; print ''; print ''; if (!$conf->expedition_bon->enabled && ! empty($conf->stock->enabled)) { print ''; } print ''; print ''; print ''; print '"; print ""; print "\n"; print '\n"; print ''; if (!$conf->expedition_bon->enabled && ! empty($conf->stock->enabled)) { print ''; print ''; } print "\n"; if ($commande->note) { print '"; } print "
'.$langs->trans("Customer").''.$soc->name.''; print "
".$langs->trans("Date")."".dol_print_date($commande->date,'dayhourtext')."'.$langs->trans("Order").''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.''; print "
'.$langs->trans("Warehouse").''; $ents = $entrepot->list_array(); print ''.img_object($langs->trans("ShowWarehouse"),'stock').' '.$ents[$_GET["entrepot_id"]].''; print '".$langs->trans("Author")."".$author->getFullName($langs)."
Note : '.nl2br($commande->note)."
"; /* * Lignes de commandes */ print '
'; $commande->fetch_lines(1); $lines = $commande->lines; // Lecture des livraisons deja effectuees $commande->livraison_array(); $num = count($commande->lines); $i = 0; if ($num) { print ''; print ''; print ''; print ''; print ''; if (! empty($conf->stock->enabled)) { print ''; } print "\n"; } $var=true; while ($i < $num) { $product = new Product($db); $line = $commande->lines[$i]; $var=!$var; print "\n"; if ($line->fk_product > 0) { $product->fetch($line->fk_product); $product->load_stock(); // Define output language if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $commande->fetch_thirdparty(); $outputlangs = $langs; $newlang=''; if (empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if (empty($newlang)) $newlang=$commande->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $label = (! empty($product->multilangs[$outputlangs->defaultlang]["label"])) ? $product->multilangs[$outputlangs->defaultlang]["label"] : $product->label; } else $label = (! empty($line->label)?$line->label:$product->label); print ''; } else { print "\n"; } print ''; /* * */ print ''; $quantite_commandee = $line->qty; $quantite_a_livrer = $quantite_commandee - $quantite_livree; if (! empty($conf->stock->enabled)) { $stock = $product->stock_warehouse[$_GET["entrepot_id"]]->real; $stock+=0; // Convertit en numerique // Quantite a livrer print ''; // Stock if ($stock < $quantite_a_livrer) { print ''; } else { print ''; } } else { // Quantite a livrer print ''; } print "\n"; $i++; $var=!$var; } /* * */ print ''; print "
'.$langs->trans("Description").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyReceived").''.$langs->trans("QtyToShip").''.$langs->trans("Stock").'
'; print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$label; if ($line->description) print nl2br($line->description); print '"; if ($line->fk_product_type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); if (! empty($line->label)) { $text.= ' '.$line->label.''; print $form->textwithtooltip($text,$line->description,3,'','',$i); } else { print $text.' '.nl2br($line->description); } print_date_range($lines[$i]->date_start,$lines[$i]->date_end); print "'.$line->qty.''; $quantite_livree = $commande->livraisons[$line->id]; print $quantite_livree; print ''; print ''; print ''; print ''.$stock.' '.img_warning().''.$stock.''; print ''; print ''; print '

"; print '
'; } else { dol_print_error($db); } } else /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ { if ($object->id > 0) { // Origin of a 'livraison' (delivery) is ALWAYS 'expedition' (shipment). // However, origin of shipment in future may differs (commande, proposal, ...) // TODO REGIS: // Je ne suis pas d'accord, beaucoup entreprises n'utilisent pas les bons d'expéditions car ces derniers sont gérés par le transporteur, // donc les bons de livraisons peuvent avoir une origine différente de 'expedition' // les bons de livraisons et d'expéditions devraient être considérés comme des objets à part entière, voir des modules différents comme une propal ou autres. $expedition=new Expedition($db); $result = $expedition->fetch($object->origin_id); $typeobject = $expedition->origin; // example: commande if ($object->origin_id > 0) { $object->fetch_origin(); } if ($object->id > 0) { $soc = new Societe($db); $soc->fetch($object->socid); $head=delivery_prepare_head($object); dol_fiche_head($head, 'delivery', $langs->trans("Shipment"), 0, 'sending'); /* * Confirmation de la suppression * */ if ($action == 'delete') { $expedition_id = GETPOST("expid"); print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&expid='.$expedition_id.'&backtopage='.urlencode($backtopage),$langs->trans("DeleteDeliveryReceipt"),$langs->trans("DeleteDeliveryReceiptConfirm",$object->ref),'confirm_delete','','',1); } /* * Confirmation de la validation */ if ($action == 'valid') { print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans("ValidateDeliveryReceipt"),$langs->trans("ValidateDeliveryReceiptConfirm",$object->ref),'confirm_valid','','',1); } /* * Livraison */ print ''; // Shipment if (($object->origin == 'shipment' || $object->origin == 'expedition') && $object->origin_id > 0) { $linkback = ''.$langs->trans("BackToList").''; // Ref print ''; print ''; } // Ref print ''; print ''; // Client print ''; print ''; print ""; // Document origine if ($typeobject == 'commande' && $expedition->origin_id && ! empty($conf->commande->enabled)) { print ''; $order=new Commande($db); $order->fetch($expedition->origin_id); print '\n"; print ''; } if ($typeobject == 'propal' && $expedition->origin_id && ! empty($conf->propal->enabled)) { $propal=new Propal($db); $propal->fetch($expedition->origin_id); print ''; print '\n"; print ''; } // Ref client print ''; print '\n"; print ''; // Date print ''; print '\n"; print ''; // Date delivery real / Received print ''; print ''; // Incoterms if (!empty($conf->incoterm->enabled)) { print ''; print ''; } // Note Public print ''; print '"; // Note Private print ''; print '"; // Statut print ''; print '\n"; print ''; if (!$conf->expedition_bon->enabled && ! empty($conf->stock->enabled)) { // Entrepot $entrepot = new Entrepot($db); $entrepot->fetch($object->entrepot_id); print ''; print ''; print ''; } print "
'.$langs->trans("RefSending").''; // Nav is hidden because on a delivery receipt of a shipment, if we go on next shipment, we may find no tab (a shipment may not have delivery receipt yet) //print $form->showrefnav($expedition, 'refshipment', $linkback, 1, 'ref', 'ref'); print $form->showrefnav($expedition, 'refshipment', $linkback, 0, 'ref', 'ref'); print '
'.$langs->trans("Ref").''.$object->ref.'
'.$langs->trans("Customer").''.$soc->getNomUrl(1).'
'.$langs->trans("RefOrder").''; print $order->getNomUrl(1,'commande'); print "
'.$langs->trans("RefProposal").''; print $propal->getNomUrl(1,'expedition'); print "
'.$langs->trans("RefCustomer").''.$object->ref_customer."
'.$langs->trans("DateCreation").''.dol_print_date($object->date_creation,'daytext')."
'; print ''; if ($action != 'editdate_livraison') print ''; print '
'; print $langs->trans('DateReceived'); print 'id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'
'; print '
'; if ($action == 'editdate_livraison') { print '
'; print ''; print ''; $form->select_date($object->date_delivery?$object->date_delivery:-1,'liv_',1,1,'',"setdate_livraison"); print ''; print '
'; } else { print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhourtext') : ' '; } print '
'; print '
'; print $langs->trans('IncotermLabel'); print ''; if ($user->rights->expedition->livraison->creer) print ''.img_edit().''; else print ' '; print '
'; print '
'; if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1); } else { print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id); } print '
'.$langs->trans("NotePublic").''; print nl2br($object->note_public); /*$doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); print $doleditor->Create(1);*/ print "
'.$langs->trans("NotePrivate").''; print nl2br($object->note_private); /*$doleditor = new DolEditor('note_pprivate', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); print $doleditor->Create(1);*/ print "
'.$langs->trans("Status").''.$object->getLibStatut(4)."
'.$langs->trans("Warehouse").''.$entrepot->libelle.'

\n"; /* * Lignes produits */ $num_prod = count($object->lines); $i = 0; $total = 0; print ''; if ($num_prod) { $i = 0; print ''; print ''; print ''; print ''; print "\n"; } $var=true; while ($i < $num_prod) { $var=!$var; print ""; if ($object->lines[$i]->fk_product > 0) { $product = new Product($db); $product->fetch($object->lines[$i]->fk_product); // Define output language if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $outputlangs = $langs; $newlang=''; if (empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if (empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $label = (! empty($product->multilangs[$outputlangs->defaultlang]["label"])) ? $product->multilangs[$outputlangs->defaultlang]["label"] : $object->lines[$i]->product_label; } else $label = ( ! empty($object->lines[$i]->label)?$object->lines[$i]->label:$object->lines[$i]->product_label); print '\n"; } print ''; print ''; print ""; $i++; } print "
'.$langs->trans("Products").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyReceived").'
'; // Affiche ligne produit $text = ''; if ($object->lines[$i]->fk_product_type==1) $text.= img_object($langs->trans('ShowService'),'service'); else $text.= img_object($langs->trans('ShowProduct'),'product'); $text.= ' '.$object->lines[$i]->product_ref.''; $text.= ' - '.$label; $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($object->lines[$i]->description)); //print $description; print $form->textwithtooltip($text,$description,3,'','',$i); print_date_range($object->lines[$i]->date_start,$object->lines[$i]->date_end); if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) { print (! empty($object->lines[$i]->description) && $object->lines[$i]->description!=$object->lines[$i]->product_label)?'
'.dol_htmlentitiesbr($object->lines[$i]->description):''; } } else { print "
"; if ($object->lines[$i]->fk_product_type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); if (! empty($object->lines[$i]->label)) { $text.= ' '.$object->lines[$i]->label.''; print $form->textwithtooltip($text,$object->lines[$i]->description,3,'','',$i); } else { print $text.' '.nl2br($object->lines[$i]->description); } print_date_range($objp->date_start,$objp->date_end); print "'.$object->lines[$i]->qty_asked.''.$object->lines[$i]->qty_shipped.'
\n"; print "\n\n"; /* * Boutons actions */ if ($user->societe_id == 0) { print '
'; if ($object->statut == 0 && $num_prod > 0) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison->creer)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison_advance->validate))) { print ''.$langs->trans("Validate").''; } } if ($user->rights->expedition->livraison->supprimer) { if ($conf->expedition_bon->enabled) { print ''.$langs->trans("Delete").''; } else { print ''.$langs->trans("Delete").''; } } print '
'; } print "\n"; print '
'; /* * Documents generated */ $objectref = dol_sanitizeFileName($object->ref); $filedir = $conf->expedition->dir_output . "/receipt/" . $objectref; $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed=$user->rights->expedition->livraison->creer; $delallowed=$user->rights->expedition->livraison->supprimer; $somethingshown=$formfile->show_documents('livraison',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); /* * Linked object block (of linked shipment) */ if ($object->origin == 'expedition') { $shipment = new Expedition($db); $shipment->fetch($object->origin_id); // Linked object block $somethingshown = $form->showLinkedObjectBlock($shipment); // Show links to link elements //$linktoelem = $form->showLinkToObjectBlock($shipment); //if ($linktoelem) print '
'.$linktoelem; } print '
'; // Rien a droite print '
'; if ($expedition->origin_id) { print '
'; //show_list_sending_receive($expedition->origin,$expedition->origin_id," AND e.rowid <> ".$expedition->id); show_list_sending_receive($expedition->origin,$expedition->origin_id); } } else { /* Expedition non trouvee */ print "Expedition inexistante ou acces refuse"; } } else { /* Expedition non trouvee */ print "Expedition inexistante ou acces refuse"; } } llxFooter(); $db->close();