dolibarr  13.0.2
discount.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
30 {
34  public $db;
35 
39  public $error;
40 
44  public $errors = array();
45 
49  public $id;
50 
54  public $fk_soc;
55 
56  public $discount_type; // 0 => customer discount, 1 => supplier discount
57  public $amount_ht; //
58  public $amount_tva; //
59  public $amount_ttc; //
60  public $multicurrency_amount_ht;
61  public $multicurrency_amount_tva;
62  public $multicurrency_amount_ttc;
63  // Vat rate
64  public $tva_tx;
65  public $vat_src_code;
66 
70  public $fk_user;
71 
75  public $description;
76 
82  public $datec;
83 
87  public $fk_facture_line;
88 
92  public $fk_facture;
93 
97  public $fk_facture_source;
98  public $ref_facture_source; // Ref credit note or deposit used to create the discount
99  public $type_facture_source;
100 
101  public $fk_invoice_supplier_source;
102  public $ref_invoice_supplier_source; // Ref credit note or deposit used to create the discount
103  public $type_invoice_supplier_source;
104 
110  public function __construct($db)
111  {
112  $this->db = $db;
113  }
114 
115 
124  public function fetch($rowid, $fk_facture_source = 0, $fk_invoice_supplier_source = 0)
125  {
126  global $conf;
127 
128  // Check parameters
129  if (!$rowid && !$fk_facture_source && !$fk_invoice_supplier_source)
130  {
131  $this->error = 'ErrorBadParameters';
132  return -1;
133  }
134 
135  $sql = "SELECT sr.rowid, sr.fk_soc, sr.discount_type,";
136  $sql .= " sr.fk_user,";
137  $sql .= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx, sr.vat_src_code,";
138  $sql .= " sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,";
139  $sql .= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.fk_invoice_supplier_line, sr.fk_invoice_supplier, sr.fk_invoice_supplier_source, sr.description,";
140  $sql .= " sr.datec,";
141  $sql .= " f.ref as ref_facture_source, f.type as type_facture_source,";
142  $sql .= " fsup.ref as ref_invoice_supplier_source, fsup.type as type_invoice_supplier_source";
143  $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
144  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid";
145  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fsup ON sr.fk_invoice_supplier_source = fsup.rowid";
146  $sql .= " WHERE sr.entity IN (".getEntity('invoice').")";
147  if ($rowid) $sql .= " AND sr.rowid=".$rowid;
148  if ($fk_facture_source) $sql .= " AND sr.fk_facture_source=".$fk_facture_source;
149  if ($fk_invoice_supplier_source) $sql .= " AND sr.fk_invoice_supplier_source=".$fk_invoice_supplier_source;
150 
151  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
152  $resql = $this->db->query($sql);
153  if ($resql)
154  {
155  if ($this->db->num_rows($resql))
156  {
157  $obj = $this->db->fetch_object($resql);
158 
159  $this->id = $obj->rowid;
160  $this->fk_soc = $obj->fk_soc;
161  $this->discount_type = $obj->discount_type;
162 
163  $this->amount_ht = $obj->amount_ht;
164  $this->amount_tva = $obj->amount_tva;
165  $this->amount_ttc = $obj->amount_ttc;
166 
167  $this->multicurrency_amount_ht = $this->multicurrency_subprice = $obj->multicurrency_amount_ht;
168  $this->multicurrency_amount_tva = $obj->multicurrency_amount_tva;
169  $this->multicurrency_amount_ttc = $obj->multicurrency_amount_ttc;
170 
171  $this->tva_tx = $obj->tva_tx;
172  $this->vat_src_code = $obj->vat_src_code;
173 
174  $this->fk_user = $obj->fk_user;
175  $this->fk_facture_line = $obj->fk_facture_line;
176  $this->fk_facture = $obj->fk_facture;
177  $this->fk_facture_source = $obj->fk_facture_source; // Id credit note or deposit source
178  $this->ref_facture_source = $obj->ref_facture_source; // Ref credit note or deposit source
179  $this->type_facture_source = $obj->type_facture_source; // Type credit note or deposit source
180  $this->fk_invoice_supplier_line = $obj->fk_invoice_supplier_line;
181  $this->fk_invoice_supplier = $obj->fk_invoice_supplier;
182  $this->fk_invoice_supplier_source = $obj->fk_invoice_supplier_source; // Id credit note or deposit source
183  $this->ref_invoice_supplier_source = $obj->ref_invoice_supplier_source; // Ref credit note or deposit source
184  $this->type_invoice_supplier_source = $obj->type_invoice_supplier_source; // Type credit note or deposit source
185  $this->description = $obj->description;
186  $this->datec = $this->db->jdate($obj->datec);
187 
188  $this->db->free($resql);
189  return 1;
190  } else {
191  $this->db->free($resql);
192  return 0;
193  }
194  } else {
195  $this->error = $this->db->error();
196  return -1;
197  }
198  }
199 
200 
207  public function create($user)
208  {
209  global $conf, $langs;
210 
211  // Clean parameters
212  $this->amount_ht = price2num($this->amount_ht);
213  $this->amount_tva = price2num($this->amount_tva);
214  $this->amount_ttc = price2num($this->amount_ttc);
215 
216  $this->tva_tx = price2num($this->tva_tx);
217 
218  $this->multicurrency_amount_ht = price2num($this->multicurrency_amount_ht);
219  $this->multicurrency_amount_tva = price2num($this->multicurrency_amount_tva);
220  $this->multicurrency_amount_ttc = price2num($this->multicurrency_amount_ttc);
221 
222  if (empty($this->multicurrency_amount_ht)) $this->multicurrency_amount_ht = 0;
223  if (empty($this->multicurrency_amount_tva)) $this->multicurrency_amount_tva = 0;
224  if (empty($this->multicurrency_amount_ttc)) $this->multicurrency_amount_ttc = 0;
225  if (empty($this->tva_tx)) $this->tva_tx = 0;
226 
227  // Check parameters
228  if (empty($this->description))
229  {
230  $this->error = 'BadValueForPropertyDescription';
231  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
232  return -1;
233  }
234 
235  $userid = $user->id;
236  if (!($userid > 0)) // For example when record is saved into an anonymous context with a not loaded object $user.
237  {
238  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
239  $tmpinvoice = new Facture($this->db);
240  $tmpinvoice->fetch($this->fk_facture_source);
241  $userid = $tmpinvoice->fk_user_author; // We use the author of invoice
242  }
243 
244  // Insert request
245  $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";
246  $sql .= " (entity, datec, fk_soc, discount_type, fk_user, description,";
247  $sql .= " amount_ht, amount_tva, amount_ttc, tva_tx, vat_src_code,";
248  $sql .= " multicurrency_amount_ht, multicurrency_amount_tva, multicurrency_amount_ttc,";
249  $sql .= " fk_facture_source, fk_invoice_supplier_source";
250  $sql .= ")";
251  $sql .= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec != '' ? $this->datec : dol_now())."', ".$this->fk_soc.", ".(empty($this->discount_type) ? 0 : intval($this->discount_type)).", ".$userid.", '".$this->db->escape($this->description)."',";
252  $sql .= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.", '".$this->db->escape($this->vat_src_code)."',";
253  $sql .= " ".$this->multicurrency_amount_ht.", ".$this->multicurrency_amount_tva.", ".$this->multicurrency_amount_ttc.", ";
254  $sql .= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'" : "null").",";
255  $sql .= " ".($this->fk_invoice_supplier_source ? "'".$this->db->escape($this->fk_invoice_supplier_source)."'" : "null");
256  $sql .= ")";
257 
258  dol_syslog(get_class($this)."::create", LOG_DEBUG);
259  $resql = $this->db->query($sql);
260  if ($resql)
261  {
262  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except");
263  return $this->id;
264  } else {
265  $this->error = $this->db->lasterror().' - sql='.$sql;
266  return -1;
267  }
268  }
269 
270 
277  public function delete($user)
278  {
279  global $conf, $langs;
280 
281  // Check if we can remove the discount
282  if ($this->fk_facture_source)
283  {
284  $sql = "SELECT COUNT(rowid) as nb";
285  $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except";
286  $sql .= " WHERE (fk_facture_line IS NOT NULL"; // Not used as absolute simple discount
287  $sql .= " OR fk_facture IS NOT NULL)"; // Not used as credit note and not used as deposit
288  $sql .= " AND fk_facture_source = ".$this->fk_facture_source;
289  //$sql.=" AND rowid != ".$this->id;
290 
291  dol_syslog(get_class($this)."::delete Check if we can remove discount", LOG_DEBUG);
292  $resql = $this->db->query($sql);
293  if ($resql)
294  {
295  $obj = $this->db->fetch_object($resql);
296  if ($obj->nb > 0)
297  {
298  $this->error = 'ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved';
299  return -2;
300  }
301  } else {
302  dol_print_error($this->db);
303  return -1;
304  }
305  }
306 
307  // Check if we can remove the discount
308  if ($this->fk_invoice_supplier_source)
309  {
310  $sql = "SELECT COUNT(rowid) as nb";
311  $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except";
312  $sql .= " WHERE (fk_invoice_supplier_line IS NOT NULL"; // Not used as absolute simple discount
313  $sql .= " OR fk_invoice_supplier IS NOT NULL)"; // Not used as credit note and not used as deposit
314  $sql .= " AND fk_invoice_supplier_source = ".$this->fk_invoice_supplier_source;
315  //$sql.=" AND rowid != ".$this->id;
316 
317  dol_syslog(get_class($this)."::delete Check if we can remove discount", LOG_DEBUG);
318  $resql = $this->db->query($sql);
319  if ($resql)
320  {
321  $obj = $this->db->fetch_object($resql);
322  if ($obj->nb > 0)
323  {
324  $this->error = 'ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved';
325  return -2;
326  }
327  } else {
328  dol_print_error($this->db);
329  return -1;
330  }
331  }
332 
333  $this->db->begin();
334 
335  // Delete but only if not used
336  $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except ";
337  if ($this->fk_facture_source) $sql .= " WHERE fk_facture_source = ".$this->fk_facture_source; // Delete all lines of same serie
338  elseif ($this->fk_invoice_supplier_source) $sql .= " WHERE fk_invoice_supplier_source = ".$this->fk_invoice_supplier_source; // Delete all lines of same serie
339  else $sql .= " WHERE rowid = ".$this->id; // Delete only line
340  $sql .= " AND (fk_facture_line IS NULL"; // Not used as absolute simple discount
341  $sql .= " AND fk_facture IS NULL)"; // Not used as credit note and not used as deposit
342  $sql .= " AND (fk_invoice_supplier_line IS NULL"; // Not used as absolute simple discount
343  $sql .= " AND fk_invoice_supplier IS NULL)"; // Not used as credit note and not used as deposit
344 
345  dol_syslog(get_class($this)."::delete Delete discount", LOG_DEBUG);
346  $result = $this->db->query($sql);
347  if ($result)
348  {
349  // If source of discount was a credit note or deposit, we change source statut.
350  if ($this->fk_facture_source)
351  {
352  $sql = "UPDATE ".MAIN_DB_PREFIX."facture";
353  $sql .= " set paye=0, fk_statut=1";
354  $sql .= " WHERE (type = 2 or type = 3) AND rowid=".$this->fk_facture_source;
355 
356  dol_syslog(get_class($this)."::delete Update credit note or deposit invoice statut", LOG_DEBUG);
357  $result = $this->db->query($sql);
358  if ($result)
359  {
360  $this->db->commit();
361  return 1;
362  } else {
363  $this->error = $this->db->lasterror();
364  $this->db->rollback();
365  return -1;
366  }
367  } elseif ($this->fk_invoice_supplier_source) {
368  $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
369  $sql .= " set paye=0, fk_statut=1";
370  $sql .= " WHERE (type = 2 or type = 3) AND rowid=".$this->fk_invoice_supplier_source;
371 
372  dol_syslog(get_class($this)."::delete Update credit note or deposit invoice statut", LOG_DEBUG);
373  $result = $this->db->query($sql);
374  if ($result)
375  {
376  $this->db->commit();
377  return 1;
378  } else {
379  $this->error = $this->db->lasterror();
380  $this->db->rollback();
381  return -1;
382  }
383  } else {
384  $this->db->commit();
385  return 1;
386  }
387  } else {
388  $this->error = $this->db->lasterror();
389  $this->db->rollback();
390  return -1;
391  }
392  }
393 
394 
395 
396  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
406  public function link_to_invoice($rowidline, $rowidinvoice)
407  {
408  // phpcs:enable
409  // Check parameters
410  if (!$rowidline && !$rowidinvoice)
411  {
412  $this->error = 'ErrorBadParameters';
413  return -1;
414  }
415  if ($rowidline && $rowidinvoice)
416  {
417  $this->error = 'ErrorBadParameters';
418  return -2;
419  }
420 
421  $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
422  if (!empty($this->discount_type)) {
423  if ($rowidline) $sql .= " SET fk_invoice_supplier_line = ".$rowidline;
424  if ($rowidinvoice) $sql .= " SET fk_invoice_supplier = ".$rowidinvoice;
425  } else {
426  if ($rowidline) $sql .= " SET fk_facture_line = ".$rowidline;
427  if ($rowidinvoice) $sql .= " SET fk_facture = ".$rowidinvoice;
428  }
429  $sql .= " WHERE rowid = ".$this->id;
430 
431  dol_syslog(get_class($this)."::link_to_invoice", LOG_DEBUG);
432  $resql = $this->db->query($sql);
433  if ($resql)
434  {
435  if (!empty($this->discount_type)) {
436  $this->fk_invoice_supplier_line = $rowidline;
437  $this->fk_invoice_supplier = $rowidinvoice;
438  } else {
439  $this->fk_facture_line = $rowidline;
440  $this->fk_facture = $rowidinvoice;
441  }
442  return 1;
443  } else {
444  $this->error = $this->db->error();
445  return -3;
446  }
447  }
448 
449 
450  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
457  public function unlink_invoice()
458  {
459  // phpcs:enable
460  $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
461  if (!empty($this->discount_type)) {
462  $sql .= " SET fk_invoice_supplier_line = NULL, fk_invoice_supplier = NULL";
463  } else {
464  $sql .= " SET fk_facture_line = NULL, fk_facture = NULL";
465  }
466  $sql .= " WHERE rowid = ".$this->id;
467 
468  dol_syslog(get_class($this)."::unlink_invoice", LOG_DEBUG);
469  $resql = $this->db->query($sql);
470  if ($resql)
471  {
472  return 1;
473  } else {
474  $this->error = $this->db->error();
475  return -3;
476  }
477  }
478 
479 
491  public function getAvailableDiscounts($company = '', $user = '', $filter = '', $maxvalue = 0, $discount_type = 0, $multicurrency = 0)
492  {
493  global $conf;
494 
495  dol_syslog(get_class($this)."::getAvailableDiscounts discount_type=".$discount_type, LOG_DEBUG);
496 
497  $sql = "SELECT SUM(rc.amount_ttc) as amount, SUM(rc.multicurrency_amount_ttc) as multicurrency_amount";
498  $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
499  $sql .= " WHERE rc.entity = ".$conf->entity;
500  $sql .= " AND rc.discount_type=".intval($discount_type);
501  if (!empty($discount_type)) {
502  $sql .= " AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)"; // Available from supplier
503  } else {
504  $sql .= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available to customer
505  }
506  if (is_object($company)) $sql .= " AND rc.fk_soc = ".$company->id;
507  if (is_object($user)) $sql .= " AND rc.fk_user = ".$user->id;
508  if ($filter) $sql .= ' AND ('.$filter.')';
509  if ($maxvalue) $sql .= ' AND rc.amount_ttc <= '.price2num($maxvalue);
510 
511  $resql = $this->db->query($sql);
512  if ($resql)
513  {
514  $obj = $this->db->fetch_object($resql);
515  //while ($obj)
516  //{
517  //print 'zz'.$obj->amount;
518  //$obj = $this->db->fetch_object($resql);
519  //}
520  if ($multicurrency)
521  {
522  return $obj->amount_multicurrency;
523  }
524 
525  return $obj->amount;
526  }
527  return -1;
528  }
529 
530 
539  public function getSumDepositsUsed($invoice, $multicurrency = 0)
540  {
541  dol_syslog(get_class($this)."::getSumDepositsUsed", LOG_DEBUG);
542 
543  if ($invoice->element == 'facture' || $invoice->element == 'invoice')
544  {
545  $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
546  $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f';
547  $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id;
548  $sql .= ' AND f.type = 3';
549  } elseif ($invoice->element == 'invoice_supplier')
550  {
551  $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
552  $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f';
553  $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id;
554  $sql .= ' AND f.type = 3';
555  } else {
556  $this->error = get_class($this)."::getSumDepositsUsed was called with a bad object as a first parameter";
557  dol_print_error($this->error);
558  return -1;
559  }
560 
561  $resql = $this->db->query($sql);
562  if ($resql)
563  {
564  $obj = $this->db->fetch_object($resql);
565  if ($multicurrency == 1) return $obj->multicurrency_amount;
566  else return $obj->amount;
567  } else {
568  $this->error = $this->db->lasterror();
569  return -1;
570  }
571  }
572 
580  public function getSumCreditNotesUsed($invoice, $multicurrency = 0)
581  {
582  dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG);
583 
584  if ($invoice->element == 'facture' || $invoice->element == 'invoice')
585  {
586  $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
587  $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f';
588  $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id;
589  $sql .= ' AND f.type IN ('.$invoice::TYPE_STANDARD.', '.$invoice::TYPE_CREDIT_NOTE.', '.$invoice::TYPE_SITUATION.')'; // Find discount coming from credit note or excess received
590  } elseif ($invoice->element == 'invoice_supplier')
591  {
592  $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
593  $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f';
594  $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id;
595  $sql .= ' AND f.type IN ('.$invoice::TYPE_STANDARD.', '.$invoice::TYPE_CREDIT_NOTE.')'; // Find discount coming from credit note or excess paid
596  } else {
597  $this->error = get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter";
598  dol_print_error($this->error);
599  return -1;
600  }
601 
602  $resql = $this->db->query($sql);
603  if ($resql)
604  {
605  $obj = $this->db->fetch_object($resql);
606  if ($multicurrency == 1) return $obj->multicurrency_amount;
607  else return $obj->amount;
608  } else {
609  $this->error = $this->db->lasterror();
610  return -1;
611  }
612  }
620  public function getSumFromThisCreditNotesNotUsed($invoice, $multicurrency = 0)
621  {
622  dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG);
623 
624  if ($invoice->element == 'facture' || $invoice->element == 'invoice')
625  {
626  $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
627  $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc';
628  $sql .= ' WHERE rc.fk_facture IS NULL AND rc.fk_facture_source = '.$invoice->id;
629  } elseif ($invoice->element == 'invoice_supplier')
630  {
631  $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
632  $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc';
633  $sql .= ' WHERE rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_source = '.$invoice->id;
634  } else {
635  $this->error = get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter";
636  dol_print_error($this->error);
637  return -1;
638  }
639 
640  $resql = $this->db->query($sql);
641  if ($resql)
642  {
643  $obj = $this->db->fetch_object($resql);
644  if ($multicurrency) return $obj->multicurrency_amount;
645  else return $obj->amount;
646  } else {
647  $this->error = $this->db->lasterror();
648  return -1;
649  }
650  }
651 
659  public function getNomUrl($withpicto, $option = 'invoice')
660  {
661  global $langs;
662 
663  $result = '';
664  $link = '';
665  $linkend = '';
666  $label = '';
667  $picto = '';
668  $ref = '';
669 
670  if ($option == 'invoice') {
671  $facid = !empty($this->discount_type) ? $this->fk_invoice_supplier_source : $this->fk_facture_source;
672  $link = !empty($this->discount_type) ? '/fourn/facture/card.php' : '/compta/facture/card.php';
673  $label = $langs->trans("ShowSourceInvoice").': '.$this->ref_facture_source;
674  $link = '<a href="'.DOL_URL_ROOT.$link.'?facid='.$facid.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
675  $linkend = '</a>';
676  $ref = !empty($this->discount_type) ? $this->ref_invoice_supplier_source : $this->ref_facture_source;
677  $picto = 'bill';
678  }
679  if ($option == 'discount') {
680  $label = $langs->trans("Discount");
681  $link = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$this->fk_soc.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
682  $linkend = '</a>';
683  $ref = $langs->trans("Discount");
684  $picto = 'generic';
685  }
686 
687 
688  if ($withpicto) $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
689  if ($withpicto && $withpicto != 2) $result .= ' ';
690  $result .= $link.$ref.$linkend;
691  return $result;
692  }
693 
694 
702  public function initAsSpecimen()
703  {
704  global $user, $langs, $conf;
705 
706  $this->fk_soc = 1;
707  $this->amount_ht = 10;
708  $this->amount_tva = 1.96;
709  $this->amount_ttc = 11.96;
710  $this->tva_tx = 19.6;
711  $this->description = 'Specimen discount';
712  }
713 }
getSumCreditNotesUsed($invoice, $multicurrency=0)
Return amount (with tax) of all credit notes invoices + excess received used by invoice as a payment...
getSumDepositsUsed($invoice, $multicurrency=0)
Return amount (with tax) of all deposits invoices used by invoice as a payment.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
initAsSpecimen()
Initialise an instance with random values.
dol_now($mode= 'auto')
Return date for now.
fetch($rowid, $fk_facture_source=0, $fk_invoice_supplier_source=0)
Load object from database into memory.
$conf db
API class for accounts.
Definition: inc.php:54
getAvailableDiscounts($company= '', $user= '', $filter= '', $maxvalue=0, $discount_type=0, $multicurrency=0)
Return amount (with tax) of discounts currently available for a company, user or other criteria...
getNomUrl($withpicto, $option= 'invoice')
Return clickable ref of object (with picto or not)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
create($user)
Create a discount into database.
getSumFromThisCreditNotesNotUsed($invoice, $multicurrency=0)
Return amount (with tax) of all converted amount for this credit note.
link_to_invoice($rowidline, $rowidinvoice)
Link the discount to a particular invoice line or a particular invoice.
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...
Class to manage absolute discounts.
Class to manage invoices.
__construct($db)
Constructor.
unlink_invoice()
Link the discount to a particular invoice line or a particular invoice.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...