diff --git a/htdocs/core/lib/fichinter.lib.php b/htdocs/core/lib/fichinter.lib.php index 8507a85292a..fcb14be9c67 100644 --- a/htdocs/core/lib/fichinter.lib.php +++ b/htdocs/core/lib/fichinter.lib.php @@ -2,8 +2,9 @@ /* Copyright (C) 2006-2007 Laurent Destailleur * Copyright (C) 2007 Rodolphe Quiedeville * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2016 Gilles Poirier - + * Copyright (C) 2016 Gilles Poirier + * Copyright (C) 2018 charlene Benke + * * 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 @@ -162,4 +163,23 @@ function fichinter_admin_prepare_head() return $head; } +function fichinter_rec_prepare_head ($object) +{ + global $langs, $conf; //, $user; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id; + $head[$h][1] = $langs->trans("CardFichinter"); + $head[$h][2] = 'card'; + $h++; + + complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec'); + + complete_head_from_modules($conf, $langs, $object, $head, $h,'intervention-rec','remove'); + + + return $head; +} diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index a6f19a68086..6d32dc10402 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -785,7 +785,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/fichinter/index.php?leftmenu=ficheinter", $langs->trans("Interventions"), 0, $user->rights->ficheinter->lire, '', $mainmenu, 'ficheinter', 2200); $newmenu->add("/fichinter/card.php?action=create&leftmenu=ficheinter", $langs->trans("NewIntervention"), 1, $user->rights->ficheinter->creer, '', '', '', 201); $newmenu->add("/fichinter/list.php?leftmenu=ficheinter", $langs->trans("List"), 1, $user->rights->ficheinter->lire, '', '', '', 202); - + $newmenu->add("/fichinter/card-red.php?leftmenu=ficheinter", $langs->trans("ModelList"), 1, $user->rights->ficheinter->lire, '', '', '', 203); $newmenu->add("/fichinter/stats/index.php?leftmenu=ficheinter", $langs->trans("Statistics"), 1, $user->rights->fournisseur->commande->lire); } diff --git a/htdocs/fichinter/card-rec.php b/htdocs/fichinter/card-rec.php new file mode 100644 index 00000000000..96d7e106b5a --- /dev/null +++ b/htdocs/fichinter/card-rec.php @@ -0,0 +1,976 @@ + + * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013 Juanjo Menent + * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2012 Cedric Salvador + * Copyright (C) 2015 Alexandre Spangaro + * Copyright (C) 2016-2018 Charlie Benke + * + * 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 fichinter/card-rec.php + * \ingroup fichinter + * \brief Page to show predefined fichinter + */ + +$res=0; +if (! $res && file_exists("../../main.inc.php")) + $res=@include("../../main.inc.php"); // For root directory +if (! $res && file_exists("../../../main.inc.php")) + $res=@include("../../../main.inc.php"); // For "custom" directory + +require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinterrec.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php'; + +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +if (! empty($conf->projet->enabled)) { + require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; + require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; +} +if (! empty($conf->contrat->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; + require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcontract.class.php'; +} + + +$langs->load('bills'); +$langs->load('compta'); +$langs->load('admin'); +$langs->load("interventions"); + +// Security check +$id=(GETPOST('fichinterid', 'int')?GETPOST('fichinterid', 'int'):GETPOST('id', 'int')); +$action=GETPOST('action', 'alpha'); +if ($user->societe_id) $socid=$user->societe_id; +$objecttype = 'fichinter_rec'; +if ($action == "create" || $action == "add") $objecttype = ''; +$result = restrictedArea($user, 'ficheinter', $id, $objecttype); + +if ($page == -1) + $page = 0 ; + +$limit = GETPOST('limit')?GETPOST('limit', 'int'):$conf->liste_limit; +$offset = $limit * $page ; + +if ($sortorder == "") + $sortorder="DESC"; + +if ($sortfield == "") + $sortfield="f.datec"; + +$object = new FichinterRec($db); + + +$arrayfields=array( + 'f.titre'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), + 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1), + 'f.fk_contrat'=>array('label'=>$langs->trans("Contract"), 'checked'=>1), + 'f.duree'=>array('label'=>$langs->trans("Duration"), 'checked'=>1), + 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1), + 'f.frequency'=>array('label'=>$langs->trans("RecurringInvoiceTemplate"), 'checked'=>1), + 'f.nb_gen_done'=>array('label'=>$langs->trans("NbOfGenerationDone"), 'checked'=>1), + 'f.date_last_gen'=>array('label'=>$langs->trans("DateLastGeneration"), 'checked'=>1), + 'f.date_when'=>array('label'=>$langs->trans("NextDateToExecution"), 'checked'=>1), + 'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), + 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), +); + + +/* + * Actions + */ + + +// Create predefined intervention +if ($action == 'add') { + if (! GETPOST('titre')) { + setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Title")), null, 'errors'); + $action = "create"; + $error++; + } + + if (! GETPOST('socid')) { + setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Customer")), null, 'errors'); + $action = "create"; + $error++; + } + + // gestion des fréquences et des échéances + $frequency=GETPOST('frequency', 'int'); + $reyear=GETPOST('reyear'); + $remonth=GETPOST('remonth'); + $reday=GETPOST('reday'); + $rehour=GETPOST('rehour'); + $remin=GETPOST('remin'); + $nb_gen_max = (GETPOST('nb_gen_max', 'int')?GETPOST('nb_gen_max', 'int'):0); + if (GETPOST('frequency')) { + if (empty($reyear) || empty($remonth) || empty($reday)) { + setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Date")), null, 'errors'); + $action = "create"; + $error++; + } + if ($nb_gen_max === '') { + setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("MaxPeriodNumber")), null, 'errors'); + $action = "create"; + $error++; + } + } + + if (! $error) { + $object->id_origin = $id; + $object->titre = GETPOST('titre', 'alpha'); + $object->description = GETPOST('description', 'alpha'); + $object->socid = GETPOST('socid', 'alpha'); + $object->fk_project = GETPOST('projectid', 'int'); + $object->fk_contract = GETPOST('contractid', 'int'); + + $object->frequency = $frequency; + $object->unit_frequency = GETPOST('unit_frequency', 'alpha'); + $object->nb_gen_max = $nb_gen_max; + $object->auto_validate = GETPOST('auto_validate', 'int'); + + $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear); + $object->date_when = $date_next_execution; + + if ($object->create($user) > 0) { + $id = $object->id; + $action = ''; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + $action = "create"; + } + } +} elseif ($action == 'createfrommodel') { + $newinter = new fichinter($db); + + // on récupère les enregistrements + $object->fetch($id); + + + // on transfert les données de l'un vers l'autre + if ($object->socid > 0) { + $newinter->socid=$object->socid; + $newinter->fk_projet=$object->fk_projet; + $newinter->fk_contrat=$object->fk_contrat; + } else + $newinter->socid=GETPOST("socid"); + + $newinter->entity=$object->entity; + $newinter->duree=$object->duree; + + $newinter->description=$object->description; + $newinter->note_private=$object->note_private; + $newinter->note_public=$object->note_public; + + // on créer un nouvelle intervention + $extrafields = new ExtraFields($db); + $extralabels = $extrafields->fetch_name_optionals_label($newinter->table_element); + $array_options = $extrafields->getOptionalsFromPost($extralabels); + $newinter->array_options = $array_options; + + $newfichinterid = $newinter->create($user); + + if ($newfichinterid > 0) { + // on ajoute les lignes de détail ensuite + foreach ($object->lines as $ficheinterligne) + $newinter->addline($user, $newfichinterid, $ficheinterligne->desc, "", $ficheinterligne->duree, ''); + + // on update le nombre d'inter crée à partir du modèle + $object->updateNbGenDone(); + //on redirige vers la fiche d'intervention nouvellement crée + header('Location: '.DOL_URL_ROOT.'/fichinter/card.php?id='.$newfichinterid); + exit; + } else { + setEventMessages($newinter->error, $newinter->errors, 'errors'); + $action=''; + } +} elseif ($action == 'delete' && $user->rights->ficheinter->supprimer) { + // delete modele + $object->fetch($id); + $object->delete(); + $id = 0 ; + header('Location: '.$_SERVER["PHP_SELF"]); + exit; +} elseif ($action == 'setfrequency' && $user->rights->ficheinter->creer) { + // Set frequency and unit frequency + $object->fetch($id); + $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha')); +} elseif ($action == 'setdate_when' && $user->rights->ficheinter->creer) { + // Set next date of execution + $object->fetch($id); + $date = dol_mktime( + GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, + GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear') + ); + if (!empty($date)) $object->setNextDate($date); +} elseif ($action == 'setnb_gen_max' && $user->rights->ficheinter->creer) { +// Set max period + $object->fetch($id); + $object->setMaxPeriod(GETPOST('nb_gen_max', 'int')); +} + + +/* + * View + */ + +llxHeader('', $langs->trans("RepeatableInterventional"), 'ch-fichinter.html#s-fac-fichinter-rec'); + +$form = new Form($db); +$companystatic = new Societe($db); +if (! empty($conf->contrat->enabled)) + $contratstatic = new Contrat($db); +if (! empty($conf->projet->enabled)) + $projectstatic = new Project($db); + +$now = dol_now(); +$tmparray=dol_getdate($now); +$today = dol_mktime( + 23, 59, 59, + $tmparray['mon'], $tmparray['mday'], $tmparray['year'] +); // Today is last second of current day + + + +/* + * Create mode + */ +if ($action == 'create') { + print load_fiche_titre($langs->trans("CreateRepeatableIntervention"), '', 'title_commercial.png'); + + $object = new Fichinter($db); // Source invoice + //$object = new Managementfichinter($db); // Source invoice + + if ($object->fetch($id, $ref) > 0) { + print '
'; + print ''; + print ''; + print ''; + + dol_fiche_head(); + + $rowspan=4; + if (! empty($conf->projet->enabled) && $object->fk_project > 0) $rowspan++; + if (! empty($conf->contrat->enabled) && $object->fk_contrat > 0) $rowspan++; + + print ''; + + $object->fetch_thirdparty(); + + // Third party + print ''; + + // Title + print ''; + + // Note + print ''; + + // Author + print ""; + + if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) { + // Duration + print ''; + print ''; + print ''; + } + + // Project + if (! empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); + print ""; + } + + // Contrat + if (! empty($conf->contrat->enabled)) { + $formcontract = new FormContract($db); + print ""; + } + print "
'.$langs->trans("Customer").''; + print $form->select_company($object->thirdparty->id, 'socid', '', 0, 1); + +// .$object->thirdparty->getNomUrl(1,'customer'). + print ''; + print $langs->trans("Comment"); + print '
'.$langs->trans("Title").''; + print ''; + print ''; + print ''; + print '
".$langs->trans("Author")."".$user->getFullName($langs)."
'.$langs->trans("TotalDuration").''.convertSecondToTime( + $object->duration, 'all', + $conf->global->MAIN_DURATION_OF_WORKDAY + ).'
".$langs->trans("Project").""; + $projectid = GETPOST('projectid')?GETPOST('projectid'):$object->fk_project; + + $numprojet = $formproject->select_projects( + $object->thirdparty->id, $projectid, 'projectid', + 0, 0, 1, 0, 0, 0, 0, '', 0, 0, '' + ); + print '   '; + print $langs->trans("AddProject").''; + print "
".$langs->trans("Contract").""; + $contractid = GETPOST('contractid')?GETPOST('contractid'):$object->fk_contract; + $numcontract = $formcontract->select_contract($object->thirdparty->id, $contractid, 'contracttid'); + print "
"; + + print '

'; + + /// frequency & duration + // Autogeneration + $title = $langs->trans("Recurrence"); + print load_fiche_titre($title, '', 'calendar'); + + print ''; + + // Frequency + print '"; + + // First date of execution for cron + print ""; + + // Number max of generation + print ""; + + print "
'; + print $form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency')); + print ""; + print " "; + print $form->selectarray( + 'unit_frequency', + array('d'=>$langs->trans('Day'), 'm'=>$langs->trans('Month'), 'y'=>$langs->trans('Year')), + (GETPOST('unit_frequency')?GETPOST('unit_frequency'):'m') + ); + print "
".$langs->trans('NextDateToExecution').""; + if ($date_next_execution != "") + $date_next_execution = (GETPOST('remonth') ? dol_mktime( + 12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear') + ) : -1); + print $form->select_date($date_next_execution, '', 1, 1, '', "add", 1, 1, 1); + print "
".$langs->trans("MaxPeriodNumber").""; + print ''; + print "
"; + + print '
'; + + $title = $langs->trans("ProductsAndServices"); + if (empty($conf->service->enabled)) + $title = $langs->trans("Products"); + else if (empty($conf->product->enabled)) + $title = $langs->trans("Services"); + + print load_fiche_titre($title, '', ''); + + /* + * Invoice lines + */ + print ''; + print ''; + + print "
'; + + $sql = 'SELECT l.*'; + $sql.= " FROM ".MAIN_DB_PREFIX."fichinterdet as l"; + $sql.= " WHERE l.fk_fichinter= ".$object->id; + $sql.= " AND l.fk_product is null "; + $sql.= " ORDER BY l.rang"; + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; $total = 0; + + echo ''; + if ($num) { + print ''; + print ''; + print ''; + print "\n"; + } + $var=true; + while ($i < $num) { + $objp = $db->fetch_object($result); + $var=!$var; + print ""; + + // Show product and description + + print ''; + print ""; + + $i++; + } + $db->free($result); + + } else + print $db->error(); + print "
'.$langs->trans("Description").''.$langs->trans("Duration").'
'; + print ''; // ancre pour retourner sur la ligne + + $text = img_object($langs->trans('Service'), 'service'); + + print $text.' '.nl2br($objp->description); + + // Qty + print ''.convertSecondToTime($objp->duree).'
"; + + print '
\n"; + + dol_fiche_end(); + + print '
'; + print '     '; + print ''; + print '
'; + print "
\n"; + } + else + dol_print_error('', "Error, no invoice ".$object->id); + +} elseif ($action == 'selsocforcreatefrommodel') { + print load_fiche_titre($langs->trans("CreateRepeatableIntervention"), '', 'title_commercial.png'); + dol_fiche_head(''); + + print '
'; + print ''; + print ''; + print '
'.$langs->trans("ThirdParty").''; + print $form->select_company('', 'socid', '', 1, 1); + print '
'; + + dol_fiche_end(); + + print '
'; + print ''; + print ''; + print ''; + print '
'; + + print '
'; +} else { + /* + * View mode + * + */ + if ($id > 0) { + if ($object->fetch($id) > 0) { + $object->fetch_thirdparty(); + + $author = new User($db); + $author->fetch($object->user_author); + + $head = fichinter_rec_prepare_head($object); + + dol_fiche_head($head, 'card', $langs->trans("PredefinedInterventional"), 0, 'intervention'); + + // Intervention card + $linkback = ''.$langs->trans("BackToList").''; + + $morehtmlref='
'; + // Thirdparty + + $morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); + // Project + if (! empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($user->rights->ficheinter->creer) { + if ($action != 'classify') { + $morehtmlref.=''; + $morehtmlref.=img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; + } + if ($action == 'classify') { + + $morehtmlref.='
'; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects( + $object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1 + ); + $morehtmlref.=''; + $morehtmlref.='
'; + } else { + $morehtmlref.=$form->form_project( + $_SERVER['PHP_SELF'].'?id='.$object->id, + $object->socid, $object->fk_project, + 'none', 0, 0, 0, 1 + ); + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.='trans('ShowProject').'">'; + $morehtmlref.=$proj->ref; + $morehtmlref.=''; + } else { + $morehtmlref.=''; + } + } + } + $morehtmlref.='
'; + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + + print '
'; + print '
'; + print '
'; + + print ''; + + print ""; + + if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) { + // Duration + print ''; + print ''; + } + + print '"; + + // Contrat + if (! empty($conf->contrat->enabled)) { + $langs->load('contrat'); + print ''; + print ''; + print ''; + + } + print "
".$langs->trans("Author").''.$author->getFullName($langs)."
'.$langs->trans("TotalDuration").''; + print convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY); + print '
'.$langs->trans("Description").''.nl2br($object->description)."
'; + + print ''; + if ($action != 'contrat') { + print ''; + } + print '
'; + print $langs->trans('Contract'); + print 'id.'">'; + print img_edit($langs->trans('SetContract'), 1); + print '
'; + print '
'; + if ($action == 'contrat') { + $formcontract= new Formcontract($db); + $formcontract->formSelectContract( + $_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, + $object->fk_contrat, 'contratid', 0, 1 + ); + } else { + if ($object->fk_contrat) { + $contratstatic = new Contrat($db); + $contratstatic->fetch($object->fk_contrat); + print $contratstatic->getNomUrl(0, '', 1); + } else + print " "; + + } + print '
"; + print '
'; + + print '
'; + print '
'; + print '
'; + + print ''; + + $title = $langs->trans("Recurrence"); + print load_fiche_titre($title, '', 'calendar'); + + print '
'; + + // if "frequency" is empty or = 0, the reccurence is disabled + print ''; + + // Date when + print ''; + print ''; + + // Max period / Rest period + print ''; + print ''; + + print '
'; + print ''; + if ($action != 'editfrequency' && $user->rights->ficheinter->creer) { + print ''; + } + print '
'; + print $langs->trans('Frequency'); + print ''; + print img_edit($langs->trans('Edit'), 1) . '
'; + print '
'; + if ($action == 'editfrequency') { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + print " "; + print $form->selectarray( + 'unit_frequency', + array('d'=>$langs->trans('Day'), 'm'=>$langs->trans('Month'), 'y'=>$langs->trans('Year')), + ($object->unit_frequency?$object->unit_frequency:'m') + ); + print '
'; + } else { + if ($object->frequency > 0) + print $langs->trans('FrequencyPer_'.$object->unit_frequency, $object->frequency); + else + print $langs->trans("NotARecurringInterventionalTemplate"); + } + print '
'; + if ( $user->rights->ficheinter->creer && ($action == 'date_when' || $object->frequency > 0)) { + print $form->editfieldkey( + $langs->trans("NextDateToExecution"), 'date_when', $object->date_when, + $object, $user->rights->facture->creer, 'day' + ); + } else { + print $langs->trans("NextDateToExecution"); + } + print ''; + if ($action == 'date_when' || $object->frequency > 0) { + print $form->editfieldval( + $langs->trans("NextDateToExecution"), 'date_when', $object->date_when, + $object, $user->rights->facture->creer, 'day' + ); + } + print '
'; + if ($user->rights->ficheinter->creer && ($action == 'nb_gen_max' || $object->frequency > 0)) { + print $form->editfieldkey( + $langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, + $object, $user->rights->facture->creer + ); + } else + print $langs->trans("MaxPeriodNumber"); + + print ''; + if ($action == 'nb_gen_max' || $object->frequency > 0) { + print $form->editfieldval( + $langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max?$object->nb_gen_max:'', + $object, $user->rights->facture->creer + ); + } + else + print ''; + + print '
'; + + // Frequencry/Recurring section + if ($object->frequency > 0) { + print '
'; + if (empty($conf->cron->enabled)) { + $txtinfoadmin=$langs->trans( + "EnableAndSetupModuleCron", + $langs->transnoentitiesnoconv("Module2300Name") + ); + print info_admin($txtinfoadmin); + } + print '
'; + print ''; + + // Nb of generation already done + print ''; + print ''; + print ''; + + // Date last + print ''; + print ''; + print '
'.$langs->trans("NbOfGenerationDone").''; + print $object->nb_gen_done?$object->nb_gen_done:'0'; + print '
'; + print $langs->trans("DateLastGeneration"); + print ''; + print dol_print_date($object->date_last_gen, 'dayhour'); + print '
'; + print '
'; + } + + print '
'; + print '
'; + print '
'; + + print '

'; + + /* + * Lines + */ + + $title = $langs->trans("ProductsAndServices"); + if (empty($conf->service->enabled)) + $title = $langs->trans("Products"); + else if (empty($conf->product->enabled)) + $title = $langs->trans("Services"); + + print load_fiche_titre($title); + + print ''; + print ''; + print ''; + print ''; + print ''; + + $num = count($object->lines); + $i = 0; + $var=true; + while ($i < $num) { + $var=!$var; + + // Show product and description + if (isset($object->lines[$i]->product_type)) + $type=$object->lines[$i]->product_type; + else + $object->lines[$i]->fk_product_type; + // Try to enhance type detection using date_start and date_end for free lines when type + // was not saved. + if (! empty($objp->date_start)) $type=1; + if (! empty($objp->date_end)) $type=1; + + // Show line + print ""; + print ''; + + print ''; + print "\n"; + $i++; + } + print '
'.$langs->trans("Description").''.$langs->trans("Duration").'
'; + $text = img_object($langs->trans('Service'), 'service'); + print $text.' '.nl2br($object->lines[$i]->desc); + print ''.convertSecondToTime($object->lines[$i]->duree).'
'; + + /** + * Barre d'actions + */ + print '
'; + + if ($user->rights->ficheinter->creer) { + print ''; + } + + if ($user->rights->ficheinter->supprimer) { + print ''; + } + print '
'; + } else + print $langs->trans("ErrorRecordNotFound"); + + } else { + /* + * List mode + */ + $sql = "SELECT f.rowid as fich_rec, s.nom as name, s.rowid as socid, f.rowid as facid, f.titre, "; + $sql.= " f.duree, f.fk_contrat, f.fk_projet, f.frequency, f.nb_gen_done, f.nb_gen_max,"; + $sql.= " f.date_last_gen, f.date_when, f.datec"; + + $sql.= " FROM ".MAIN_DB_PREFIX."fichinter_rec as f"; + $sql.= " , ".MAIN_DB_PREFIX."societe as s "; + if (! $user->rights->societe->client->voir && ! $socid) { + $sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.entity = ".$conf->entity; + if ($socid) $sql .= " AND s.rowid = ".$socid; + if (! $user->rights->societe->client->voir && ! $socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($search_ref) $sql .= natural_search('f.titre', $search_ref); + if ($search_societe) $sql .= natural_search('s.nom', $search_societe); + if ($search_frequency == '1') $sql.= ' AND f.frequency > 0'; + if ($search_frequency == '0') $sql.= ' AND (f.frequency IS NULL or f.frequency = 0)'; + + + //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC "; + // $sql .= $db->plimit($limit + 1, $offset); + + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + print_barre_liste( + $langs->trans("RepeatableInterventional"), $page, + $_SERVER['PHP_SELF'], "&socid=$socid", $sortfield, $sortorder, + '', $num, '', 'title_commercial.png' + ); + + print $langs->trans("ToCreateAPredefinedInterventional").'

'; + + $i = 0; + print ''; + print ''; + print_liste_field_titre( + $langs->trans("Ref"), $_SERVER['PHP_SELF'], "f.titre", "", "", + 'width="200px" align="left"', $sortfiled, $sortorder + ); + + print_liste_field_titre( + $langs->trans("Company"), $_SERVER['PHP_SELF'], "s.nom", "", "", + 'width="200px" align="left"', $sortfiled, $sortorder + ); + if (! empty($conf->contrat->enabled)) + print_liste_field_titre( + $langs->trans("Contract"), $_SERVER['PHP_SELF'], + "f.fk_contrat", "", "", + 'width="100px" align="left"', $sortfiled, $sortorder + ); + + if (! empty($conf->projet->enabled)) + print_liste_field_titre( + $langs->trans("Project"), $_SERVER['PHP_SELF'], + "f.fk_project", "", "", + 'width="100px" align="left"', $sortfiled, $sortorder + ); + print_liste_field_titre( + $langs->trans("Duration"), $_SERVER['PHP_SELF'], + 'f.duree', '', '', + 'width="50px" align="right"', $sortfiled, $sortorder + ); + // Recurring or not + print_liste_field_titre( + $langs->trans("Frequency"), $_SERVER['PHP_SELF'], + "f.frequency", "", "", + 'width="100px" align="center"', $sortfiled, $sortorder + ); + print_liste_field_titre( + $langs->trans("NbOfGenerationDone"), $_SERVER['PHP_SELF'], + "f.nb_gen_done", "", "", + 'width="100px" align="center"', $sortfiled, $sortorder + ); + + print_liste_field_titre( + $langs->trans("DateLastGeneration"), $_SERVER['PHP_SELF'], + "f.date_last_gen", "", "", + 'width="100px" align="center"', $sortfiled, $sortorder + ); + print_liste_field_titre( + $langs->trans("NextDateToIntervention"), $_SERVER['PHP_SELF'], + "f.date_when", "", "", + 'width="100px" align="center"', $sortfiled, $sortorder + ); + print ''; + print "\n"; + + +// les filtres à faire ensuite + + if ($num > 0) { + $var=true; + while ($i < min($num, $limit)) { + $objp = $db->fetch_object($resql); + $var=!$var; + + print ""; + print '\n"; + if ($objp->socid) { + $companystatic->id=$objp->socid; + $companystatic->name=$objp->name; + print ''; + } else + print ''; + + if (! empty($conf->contrat->enabled)) { + print ''; + } + if (! empty($conf->projet->enabled)) { + print ''; + } + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + } else { + print ''.$langs->trans('NA').''; + print ''; + print ''; + print ''; + } + + if ($user->rights->ficheinter->creer) { + // Action column + print '"; + + print "\n"; + $i++; + } + } + } else + print ''; + + print "
'; + print img_object($langs->trans("ShowIntervention"), "intervention").' '.$objp->titre; + print "'.$companystatic->getNomUrl(1, 'customer').''.$langs->trans("None").''; + if ($objp->fk_contrat >0) { + $contratstatic->fetch($objp->fk_contrat); + print $contratstatic->getNomUrl(1); + } + print ''; + if ($objp->fk_project >0) { + $projectstatic->fecth($objp->fk_projet); + print $projectstatic->getNomUrl(1); + } + print ''.convertSecondToTime($objp->duree).''.yn($objp->frequency?1:0).''; + if ($objp->frequency) { + print $objp->nb_gen_done.($objp->nb_gen_max>0?' / '. $objp->nb_gen_max:'') ; + print ''; + print dol_print_date($db->jdate($objp->date_last_gen), 'day') ; + print ''; + print dol_print_date($db->jdate($objp->date_when), 'day'); + print ''; + print ''.$langs->trans('NA').''; + print ''; + print ''.$langs->trans('NA').''; + print ''; + if ($user->rights->ficheinter->creer) { + if (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today) { + print ''; + print $langs->trans("CreateFichInter").''; + } else + print $langs->trans("DateIsNotEnough"); + } else + print " "; + + print "
'.$langs->trans("NoneF").'
"; + $db->free($resql); + } else + dol_print_error($db); + } +} +llxFooter(); +$db->close(); diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 15b75495c38..88ceffcc7aa 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -5,7 +5,7 @@ * Copyright (C) 2011-2017 Juanjo Menent * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2018 Ferran Marcet - * Copyright (C) 2014-2015 Charlie Benke + * Copyright (C) 2014-2018 Charlene Benke * Copyright (C) 2015-2016 Abbes Bahfir * * This program is free software; you can redistribute it and/or modify @@ -1643,6 +1643,14 @@ else if ($id > 0 || ! empty($ref)) else print ''; } + // create interventional model + if ($object->statut == Fichinter::STATUS_DRAFT && $user->rights->ficheinter->creer && (count($object->lines) > 0)) { + print ''; + } + // Proposal if ($conf->service->enabled && ! empty($conf->propal->enabled) && $object->statut > Fichinter::STATUS_DRAFT) { diff --git a/htdocs/install/mysql/tables/llx_fichinter_rec.key.sql b/htdocs/install/mysql/tables/llx_fichinter_rec.key.sql new file mode 100644 index 00000000000..0c420fd6395 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_fichinter_rec.key.sql @@ -0,0 +1,30 @@ +-- ============================================================================ +-- Copyright (C) 2002-2004 Rodolphe Quiedeville +-- Copyright (C) 2004-2006 Laurent Destailleur +-- Copyright (C) 2009 Regis Houssin +-- Copyright (C) 2018 Charlene Benke +-- +-- 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 . +-- +-- ============================================================================ + + +ALTER TABLE llx_fichinter_rec ADD UNIQUE INDEX idx_fichinter_rec_uk_titre (titre, entity); + +ALTER TABLE llx_fichinter_rec ADD INDEX idx_fichinter_rec_fk_soc (fk_soc); +ALTER TABLE llx_fichinter_rec ADD INDEX idx_fichinter_rec_fk_user_author (fk_user_author); +ALTER TABLE llx_fichinter_rec ADD INDEX idx_fichinter_rec_fk_projet (fk_projet); + +ALTER TABLE llx_fichinter_rec ADD CONSTRAINT fk_fichinter_rec_fk_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid); +ALTER TABLE llx_fichinter_rec ADD CONSTRAINT fk_fichinter_rec_fk_projet FOREIGN KEY (fk_projet) REFERENCES llx_projet (rowid); diff --git a/htdocs/install/mysql/tables/llx_fichinter_rec.sql b/htdocs/install/mysql/tables/llx_fichinter_rec.sql new file mode 100644 index 00000000000..10dacbde4ee --- /dev/null +++ b/htdocs/install/mysql/tables/llx_fichinter_rec.sql @@ -0,0 +1,48 @@ +-- =========================================================================== +-- Copyright (C) 2003 Rodolphe Quiedeville +-- Copyright (C) 2012-2014 Laurent Destailleur +-- Copyright (C) 2009 Regis Houssin +-- Copyright (C) 2010 Juanjo Menent +-- Copyright (C) 2018 Charlene Benke +-- +-- 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 . +-- +-- =========================================================================== + +create table llx_fichinter_rec +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + titre varchar(50) NOT NULL, + entity integer DEFAULT 1 NOT NULL, -- multi company id + fk_soc integer DEFAULT NULL, + datec datetime, -- date de creation + + fk_contrat integer DEFAULT 0, -- contrat auquel est rattache la fiche + fk_user_author integer, -- createur + fk_projet integer, -- projet auquel est associe la facture + duree real, -- duree totale de l'intervention + description text, + modelpdf varchar(50), + note_private text, + note_public text, + + frequency integer, -- frequency (for example: 3 for every 3 month) + unit_frequency varchar(2) DEFAULT 'm', -- 'm' for month (date_when must be a day <= 28), 'y' for year, ... + date_when datetime DEFAULT NULL, -- date for next gen (when an invoice is generated, this field must be updated with next date) + date_last_gen datetime DEFAULT NULL, -- date for last gen (date with last successfull generation of invoice) + nb_gen_done integer DEFAULT NULL, -- nb of generation done (when an invoice is generated, this field must incremented) + nb_gen_max integer DEFAULT NULL, -- maximum number of generation + auto_validate integer NULL DEFAULT NULL -- statut of the generated intervention + +)ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_fichinterdet_rec.sql b/htdocs/install/mysql/tables/llx_fichinterdet_rec.sql new file mode 100644 index 00000000000..682453f2dfd --- /dev/null +++ b/htdocs/install/mysql/tables/llx_fichinterdet_rec.sql @@ -0,0 +1,63 @@ +-- =================================================================== +-- Copyright (C) 2003 Rodolphe Quiedeville +-- Copyright (C) 2009-2014 Laurent Destailleur +-- Copyright (C) 2010 Juanjo Menent +-- Copyright (C) 2010-2012 Regis Houssin +-- Copyright (C) 2012 Cédric Salvador +-- Copyright (C) 2016-2018 Charlene Benke +-- +-- 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 . +-- +-- =================================================================== + +create table llx_fichinterdet_rec +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_fichinter integer NOT NULL, + date datetime, -- date de la ligne d'intervention + description text, -- description de la ligne d'intervention + duree integer, -- duree de la ligne d'intervention + rang integer DEFAULT 0, -- ordre affichage sur la fiche + total_ht DOUBLE(24, 8) NULL DEFAULT NULL, + subprice DOUBLE(24, 8) NULL DEFAULT NULL, + fk_parent_line integer NULL DEFAULT NULL, + fk_product integer NULL DEFAULT NULL, + label varchar(255) NULL DEFAULT NULL, + tva_tx DOUBLE(6, 3) NULL DEFAULT NULL, + localtax1_tx DOUBLE(6, 3) NULL DEFAULT 0, + localtax1_type VARCHAR(1) NULL DEFAULT NULL, + localtax2_tx DOUBLE(6, 3) NULL DEFAULT 0, + localtax2_type VARCHAR(1) NULL DEFAULT NULL, + qty double NULL DEFAULT NULL, + remise_percent double NULL DEFAULT 0, + remise double NULL DEFAULT 0, + fk_remise_except integer NULL DEFAULT NULL, + price DOUBLE(24, 8) NULL DEFAULT NULL, + total_tva DOUBLE(24, 8) NULL DEFAULT NULL, + total_localtax1 DOUBLE(24, 8) NULL DEFAULT 0, + total_localtax2 DOUBLE(24, 8) NULL DEFAULT 0, + total_ttc DOUBLE(24, 8) NULL DEFAULT NULL, + product_type INTEGER NULL DEFAULT 0, + date_start datetime NULL DEFAULT NULL, + date_end datetime NULL DEFAULT NULL, + info_bits INTEGER NULL DEFAULT 0, + buy_price_ht DOUBLE(24, 8) NULL DEFAULT 0, + fk_product_fournisseur_price integer NULL DEFAULT NULL, + fk_code_ventilation integer NOT NULL DEFAULT 0, + fk_export_commpta integer NOT NULL DEFAULT 0, + special_code integer UNSIGNED NULL DEFAULT 0, + fk_unit integer NULL DEFAULT NULL, + import_key varchar(14) NULL DEFAULT NULL + +)ENGINE=innodb;