1<?php
2/* Copyright (C) 2004      Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012  Regis Houssin        <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 	   Florian Henry        <florian.henry@open-concept.pro>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21/**
22 *      \file       htdocs/expedition/note.php
23 *      \ingroup    expedition
24 *      \brief      Note card expedition
25 */
26
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
30if (!empty($conf->projet->enabled)) {
31	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
32	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
33}
34
35// Load translation files required by the page
36$langs->loadLangs(array('sendings', 'companies', 'bills', 'deliveries', 'orders', 'stocks', 'other', 'propal'));
37
38$id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
39$ref = GETPOST('ref', 'alpha');
40$action = GETPOST('action', 'aZ09');
41
42$object = new Expedition($db);
43if ($id > 0 || !empty($ref)) {
44	$object->fetch($id, $ref);
45	$object->fetch_thirdparty();
46
47	if (!empty($object->origin)) {
48		$typeobject = $object->origin;
49		$origin = $object->origin;
50		$object->fetch_origin();
51	}
52
53	// Linked documents
54	if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) {
55		$objectsrc = new Commande($db);
56		$objectsrc->fetch($object->$typeobject->id);
57	}
58	if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) {
59		$objectsrc = new Propal($db);
60		$objectsrc->fetch($object->$typeobject->id);
61	}
62
63	$upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($object->ref);
64}
65
66$permissionnote = $user->rights->expedition->creer; // Used by the include of actions_setnotes.inc.php
67
68// Security check
69if ($user->socid) {
70	$socid = $user->socid;
71}
72$result = restrictedArea($user, 'expedition', $object->id, '');
73
74
75/*
76 * Actions
77 */
78
79include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
80
81
82/*
83 * View
84 */
85
86llxHeader();
87
88$form = new Form($db);
89
90if ($id > 0 || !empty($ref)) {
91	$head = shipping_prepare_head($object);
92	print dol_get_fiche_head($head, 'note', $langs->trans("Shipment"), -1, $object->picto);
93
94
95	// Shipment card
96	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
97
98	$morehtmlref = '<div class="refidno">';
99	// Ref customer shipment
100	$morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
101	$morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
102	// Thirdparty
103	$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
104	// Project
105	if (!empty($conf->projet->enabled)) {
106		$langs->load("projects");
107		$morehtmlref .= '<br>'.$langs->trans('Project').' ';
108		if (0) {    // Do not change on shipment
109			if ($action != 'classify') {
110				$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
111			}
112			if ($action == 'classify') {
113				// $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
114				$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
115				$morehtmlref .= '<input type="hidden" name="action" value="classin">';
116				$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
117				$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
118				$morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
119				$morehtmlref .= '</form>';
120			} else {
121				$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
122			}
123		} else {
124			// We don't have project on shipment, so we will use the project or source object instead
125			// TODO Add project on shipment
126			$morehtmlref .= ' : ';
127			if (!empty($objectsrc->fk_project)) {
128				$proj = new Project($db);
129				$proj->fetch($objectsrc->fk_project);
130				$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
131				$morehtmlref .= $proj->ref;
132				$morehtmlref .= '</a>';
133			} else {
134				$morehtmlref .= '';
135			}
136		}
137	}
138	$morehtmlref .= '</div>';
139
140
141	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
142
143
144	print '<div class="underbanner clearboth"></div>';
145
146	$cssclass = 'titlefield';
147	include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
148
149	print dol_get_fiche_end();
150}
151
152// End of page
153llxFooter();
154$db->close();
155