* 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 * Copyright (C) 2015 Claudio Aschieri * * 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/delivery/card.php * \ingroup livraison * \brief Page to describe a delivery receipt */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; if (isModEnabled("product") || isModEnabled("service")) { 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 (isModEnabled('stock')) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; } if (isModEnabled('project')) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } // Load translation files required by the page $langs->loadLangs(array('bills', 'deliveries', 'orders', 'sendings')); if (isModEnabled('incoterm')) { $langs->load('incoterm'); } $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); // Security check $id = GETPOST('id', 'int'); if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'expedition', $id, 'delivery', 'delivery'); $object = new Delivery($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); // fetch optionals attributes lines and labels $extrafields->fetch_name_optionals_label($object->table_element_line); // Load object. Make an object->fetch include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('deliverycard', 'globalcard')); $error = 0; /* * Actions */ $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks // Delete Link $permissiondellink = $user->rights->expedition->delivery->supprimer; // Used by the include of actions_dellink.inc.php include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once if ($action == 'add') { $db->begin(); $object->date_delivery = dol_now(); $object->note = GETPOST("note", 'restricthtml'); $object->note_private = GETPOST("note", 'restricthtml'); $object->commande_id = GETPOST("commande_id", 'int'); $object->fk_incoterms = GETPOST('incoterm_id', 'int'); if (!$conf->expedition_bon->enabled && isModEnabled('stock')) { $expedition->entrepot_id = GETPOST('entrepot_id', 'int'); } // We loop on each line of order to complete object delivery with qty to delivery $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; $qtytouse = price2num(GETPOST($qty)); if ($qtytouse > 0) { $object->addline(GETPOST($idl), price2num($qtytouse), $arrayoptions); } } $ret = $object->create($user); if ($ret > 0) { $db->commit(); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); $db->rollback(); $action = 'create'; } } elseif ($action == 'confirm_valid' && $confirm == 'yes' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) ) { $result = $object->valid($user); // Define output language if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { $newlang = GETPOST('lang_id', 'aZ09'); } if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { $newlang = $object->thirdparty->default_lang; } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } $model = $object->model_pdf; $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->delivery->supprimer) { $db->begin(); $result = $object->delete(); if ($result > 0) { $db->commit(); if (!empty($backtopage)) { header("Location: ".$backtopage); } else { header("Location: ".DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'); } exit; } else { $db->rollback(); } } if ($action == 'setdate_delivery' && $user->rights->expedition->delivery->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->setDeliveryDate($user, $datedelivery); if ($result < 0) { $mesg = '
'.$object->error.'
'; } } elseif ($action == 'set_incoterms' && isModEnabled('incoterm')) { // Set incoterm $result = $object->setIncoterms((int) GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); } // Update extrafields if ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); if ($ret < 0) { $error++; } if (!$error) { // Actions on extra fields $result = $object->insertExtraFields('DELIVERY_MODIFY'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } } if ($error) { $action = 'edit_extras'; } } // Extrafields line if ($action == 'update_extras_line') { $array_options = array(); $num = count($object->lines); for ($i = 0; $i < $num; $i++) { // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); $array_options[$i] = $extrafields->getOptionalsFromPost($extralabelsline, $i); // Unset extrafield if (is_array($extralabelsline)) { // Get extra fields foreach ($extralabelsline as $key => $value) { unset($_POST["options_".$key]); } } $ret = $object->update_line($object->lines[$i]->id, $array_options[$i]); // extrafields update if ($ret < 0) { $mesg = '
'.$object->error.'
'; $error++; } } } // Actions to build doc $upload_dir = $conf->expedition->dir_output.'/receipt'; $permissiontoadd = $user->rights->expedition->creer; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; /* * View */ $title = $langs->trans('Delivery'); llxHeader('', $title, 'Livraison'); $form = new Form($db); $formfile = new FormFile($db); if ($action == 'create') { // Create. Seems to no be used } else { // View if ($object->id > 0) { // Origin of a 'livraison' (delivery receipt) is ALWAYS 'expedition' (shipment). // However, origin of shipment in future may differs (commande, proposal, ...) $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); print '
'; print ''; print ''; print ''; print ''; print ''; print dol_get_fiche_head($head, 'delivery', $langs->trans("Shipment"), -1, 'dolly'); /* * 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); } /* * Delivery */ if ($typeobject == 'commande' && $expedition->origin_id > 0 && isModEnabled('commande')) { $objectsrc = new Commande($db); $objectsrc->fetch($expedition->origin_id); } if ($typeobject == 'propal' && $expedition->origin_id > 0 && isModEnabled("propal")) { $objectsrc = new Propal($db); $objectsrc->fetch($expedition->origin_id); } // Shipment card $linkback = ''.$langs->trans("BackToList").''; $morehtmlref = '
'; // Ref customer shipment $morehtmlref .= $form->editfieldkey("RefCustomer", '', $expedition->ref_customer, $expedition, $user->rights->expedition->creer, 'string', '', 0, 1); $morehtmlref .= $form->editfieldval("RefCustomer", '', $expedition->ref_customer, $expedition, $user->rights->expedition->creer, 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE : ''), '', null, null, '', 1); $morehtmlref .= '
'.$langs->trans("RefDeliveryReceipt").' : '.$object->ref; // Thirdparty $morehtmlref .= '
'.$expedition->thirdparty->getNomUrl(1); // Project if (isModEnabled('project')) { $langs->load("projects"); $morehtmlref .= '
'; if (0) { // Do not change on shipment $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); if ($action != 'classify') { $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; } $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); } else { if (!empty($objectsrc->fk_project)) { $proj = new Project($db); $proj->fetch($objectsrc->fk_project); $morehtmlref .= $proj->getNomUrl(1); if ($proj->title) { $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; } } } } $morehtmlref .= '
'; $morehtmlstatus = $langs->trans("StatusReceipt").' : '.$object->getLibStatut(6).'

'; dol_banner_tab($expedition, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus); print '
'; print '
'; 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 && isModEnabled('commande')) { print ''; $order = new Commande($db); $order->fetch($expedition->origin_id); print '\n"; print ''; } if ($typeobject == 'propal' && $expedition->origin_id && isModEnabled("propal")) { $propal = new Propal($db); $propal->fetch($expedition->origin_id); print ''; print '\n"; print ''; } // Date print ''; print '\n"; print ''; // Date delivery real / Received print ''; print ''; // Incoterms if (isModEnabled('incoterm')) { print ''; print ''; } /* A delivery note should be just more properties of a shipment, so notes are on shipment // Note Public print ''; print '"; // Note Private print ''; print '"; */ // Statut /*print ''; print '\n"; print '';*/ if (!$conf->expedition_bon->enabled && isModEnabled('stock')) { // Entrepot $entrepot = new Entrepot($db); $entrepot->fetch($object->entrepot_id); print ''; print ''; print ''; } // Other attributes if ($action == 'create_delivery') { // copy from expedition $extrafields->fetch_name_optionals_label($expedition->table_element); if ($expedition->fetch_optionals() > 0) { $object->array_options = array_merge($object->array_options, $expedition->array_options); } } $cols = 2; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; 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").''; print $object->ref; print '
'.$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("DateCreation").''.dol_print_date($object->date_creation, 'dayhour')."
'; print ''; if ($action != 'editdate_delivery') { print ''; } print '
'; print $langs->trans('DateReceived'); print 'id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'
'; print '
'; if ($action == 'editdate_delivery') { print ''; print ''; print ''; print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, '', "setdate_delivery", 1, 1); print ''; print ''; } else { print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : ' '; } print '
'; print '
'; print $langs->trans('IncotermLabel'); print ''; if ($user->rights->expedition->delivery->creer) { print ''.img_edit().''; } else { print ' '; } print '
'; print '
'; if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->label_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); print "
'.$langs->trans("NotePrivate").''; print nl2br($object->note_private); print "
'.$langs->trans("Status").''.$object->getLibStatut(4)."
'.$langs->trans("Warehouse").''.$entrepot->label.'

\n"; print '
'; /* * Products lines */ $num_prod = count($object->lines); $i = 0; $total = 0; print ''; if ($num_prod) { $i = 0; print ''; print ''; print ''; print ''; print "\n"; } while ($i < $num_prod) { $parameters = array('i' => $i, 'line' => $object->lines[$i], 'num' => $num_prod); $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if (empty($reshook)) { print ''; if ($object->lines[$i]->fk_product > 0) { $product = new Product($db); $product->fetch($object->lines[$i]->fk_product); // Define output language if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $outputlangs = $langs; $newlang = ''; if (empty($newlang) && GETPOST('lang_id', 'aZ09')) { $newlang = GETPOST('lang_id', 'aZ09'); } if (empty($newlang)) { $newlang = $object->thirdparty->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 ""; // Display lines extrafields //if (!empty($extrafields)) { $colspan = 2; $mode = ($object->statut == 0) ? 'edit' : 'view'; $object->lines[$i]->fetch_optionals(); if ($action == 'create_delivery') { $srcLine = new ExpeditionLigne($db); $extrafields->fetch_name_optionals_label($srcLine->table_element); $srcLine->id = $expedition->lines[$i]->id; $srcLine->fetch_optionals(); $object->lines[$i]->array_options = array_merge($object->lines[$i]->array_options, $srcLine->array_options); } else { $srcLine = new DeliveryLine($db); $extrafields->fetch_name_optionals_label($srcLine->table_element); } print $object->lines[$i]->showOptionals($extrafields, $mode, array('style' => 'class="oddeven"', 'colspan' => $colspan), ''); //} } $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 = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : 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 (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) { 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 dol_get_fiche_end(); //if ($object->statut == 0) // only if draft // print $form->buttonsSaveCancel("Save", ''); print ''; /* * Boutons actions */ if ($user->socid == 0) { print '
'; if ($object->statut == 0 && $num_prod > 0) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) { print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=valid&token='.newToken().'&id='.$object->id, ''); } } if ($user->rights->expedition->delivery->supprimer) { if ($conf->expedition_bon->enabled) { print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&expid='.$object->origin_id.'&action=delete&token='.newToken().'&backtopage='.urlencode(DOL_URL_ROOT.'/expedition/card.php?id='.$object->origin_id), ''); } else { print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, ''); } } 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->delivery->lire; $delallowed = $user->rights->expedition->delivery->creer; print $formfile->showdocuments('delivery', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 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); // Show links to link elements //$linktoelem = $form->showLinkToObjectBlock($object, null, array('order')); $somethingshown = $form->showLinkedObjectBlock($object, ''); } print '
'; // Nothing on right print '
'; } else { /* Expedition non trouvee */ print "Expedition inexistante ou acces refuse"; } } else { /* Expedition non trouvee */ print "Expedition inexistante ou acces refuse"; } } // End of page llxFooter(); $db->close();