dolibarr  13.0.2
html.formcontract.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012-2018 Charlene BENKE <charlie@patas-monkey.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  * or see https://www.gnu.org/
17  */
18 
29 {
33  public $db;
34 
38  public $error = '';
39 
40 
46  public function __construct($db)
47  {
48  $this->db = $db;
49  }
50 
51 
52  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
64  public function select_contract($socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0)
65  {
66  // phpcs:enable
67  global $db, $user, $conf, $langs;
68 
69  $hideunselectables = false;
70  if (!empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
71 
72  // Search all contacts
73  $sql = 'SELECT c.rowid, c.ref, c.fk_soc, c.statut,';
74  $sql .= ' c.ref_customer, c.ref_supplier';
75  $sql .= ' FROM '.MAIN_DB_PREFIX.'contrat as c';
76  $sql .= " WHERE c.entity = ".$conf->entity;
77  //if ($contratListId) $sql.= " AND c.rowid IN (".$contratListId.")";
78  if ($socid > 0)
79  {
80  // CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
81  if (empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)) {
82  $sql .= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)";
83  } elseif ($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all') {
84  $sql .= " AND (c.fk_soc IN (".$socid.", ".$conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") ";
85  $sql .= " OR c.fk_soc IS NULL)";
86  }
87  }
88  if ($socid == 0) $sql .= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
89  $sql .= " ORDER BY c.ref ";
90 
91  dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
92  $resql = $this->db->query($sql);
93  if ($resql)
94  {
95  print '<select class="flat" name="'.$htmlname.'">';
96  if ($showempty) print '<option value="0">&nbsp;</option>';
97  $num = $this->db->num_rows($resql);
98  $i = 0;
99  if ($num)
100  {
101  while ($i < $num)
102  {
103  $obj = $this->db->fetch_object($resql);
104  // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
105  if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire)
106  {
107  // Do nothing
108  } else {
109  $labeltoshow = dol_trunc($obj->ref, 18);
110 
111  if ($showRef)
112  {
113  if ($obj->ref_customer) $labeltoshow = $labeltoshow." - ".$obj->ref_customer;
114  if ($obj->ref_supplier) $labeltoshow = $labeltoshow." - ".$obj->ref_supplier;
115  }
116 
117  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
118  //else $labeltoshow.=' ('.$langs->trans("Private").')';
119  if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
120  {
121  print '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
122  } else {
123  $disabled = 0;
124  if ($obj->statut == 0)
125  {
126  $disabled = 1;
127  $labeltoshow .= ' ('.$langs->trans("Draft").')';
128  }
129  if (empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
130  {
131  $disabled = 1;
132  $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
133  }
134 
135  if ($hideunselectables && $disabled)
136  {
137  $resultat = '';
138  } else {
139  $resultat = '<option value="'.$obj->rowid.'"';
140  if ($disabled) $resultat .= ' disabled';
141  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
142  //else $labeltoshow.=' ('.$langs->trans("Private").')';
143  $resultat .= '>'.$labeltoshow;
144  $resultat .= '</option>';
145  }
146  print $resultat;
147  }
148  }
149  $i++;
150  }
151  }
152  print '</select>';
153  $this->db->free($resql);
154 
155  if (!empty($conf->use_javascript_ajax))
156  {
157  // Make select dynamic
158  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
159  print ajax_combobox($htmlname);
160  }
161 
162  return $num;
163  } else {
164  dol_print_error($this->db);
165  return -1;
166  }
167  }
168 
181  public function formSelectContract($page, $socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1, $showRef = 0)
182  {
183  global $langs;
184 
185  print "\n";
186  print '<form method="post" action="'.$page.'">';
187  print '<input type="hidden" name="action" value="setcontract">';
188  print '<input type="hidden" name="token" value="'.newToken().'">';
189  $this->select_contract($socid, $selected, $htmlname, $maxlength, $showempty, $showRef);
190  print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
191  print '</form>';
192  }
193 }
select_contract($socid=-1, $selected= '', $htmlname= 'contrattid', $maxlength=16, $showempty=1, $showRef=0)
Show a combo list with contracts qualified for a third party.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:391
$conf db
API class for accounts.
Definition: inc.php:54
formSelectContract($page, $socid=-1, $selected= '', $htmlname= 'contrattid', $maxlength=16, $showempty=1, $showRef=0)
Show a form to select a contract.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
__construct($db)
Constructor.
Class to manage generation of HTML components for contract module.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.