commoninvoice.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <?php
  2. /* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
  3. * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
  4. * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/class/commoninvoice.class.php
  21. * \ingroup core
  22. * \brief File of the superclass of invoices classes (customer and supplier)
  23. */
  24. require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
  25. /**
  26. * Superclass for invoices classes
  27. */
  28. abstract class CommonInvoice extends CommonObject
  29. {
  30. /**
  31. * Standard invoice
  32. */
  33. const TYPE_STANDARD = 0;
  34. /**
  35. * Replacement invoice
  36. */
  37. const TYPE_REPLACEMENT = 1;
  38. /**
  39. * Credit note invoice
  40. */
  41. const TYPE_CREDIT_NOTE = 2;
  42. /**
  43. * Deposit invoice
  44. */
  45. const TYPE_DEPOSIT = 3;
  46. /**
  47. * Proforma invoice.
  48. * @deprectad Remove this. A "proforma invoice" is an order with a look of invoice, not an invoice !
  49. */
  50. const TYPE_PROFORMA = 4;
  51. /**
  52. * Situation invoice
  53. */
  54. const TYPE_SITUATION = 5;
  55. /**
  56. * Draft
  57. */
  58. const STATUS_DRAFT = 0;
  59. /**
  60. * Validated (need to be paid)
  61. */
  62. const STATUS_VALIDATED = 1;
  63. /**
  64. * Classified paid.
  65. * If paid partially, $this->close_code can be:
  66. * - CLOSECODE_DISCOUNTVAT
  67. * - CLOSECODE_BADDEBT
  68. * If paid completelly, this->close_code will be null
  69. */
  70. const STATUS_CLOSED = 2;
  71. /**
  72. * Classified abandoned and no payment done.
  73. * $this->close_code can be:
  74. * - CLOSECODE_BADDEBT
  75. * - CLOSECODE_ABANDONED
  76. * - CLOSECODE_REPLACED
  77. */
  78. const STATUS_ABANDONED = 3;
  79. /**
  80. * Return remain amount to pay. Property ->id and ->total_ttc must be set.
  81. * This does not include open direct debit requests.
  82. *
  83. * @param int $multicurrency Return multicurrency_amount instead of amount
  84. * @return double Remain of amount to pay
  85. */
  86. function getRemainToPay($multicurrency=0)
  87. {
  88. $alreadypaid=0;
  89. $alreadypaid+=$this->getSommePaiement($multicurrency);
  90. $alreadypaid+=$this->getSumDepositsUsed($multicurrency);
  91. $alreadypaid+=$this->getSumCreditNotesUsed($multicurrency);
  92. return $this->total_ttc - $alreadypaid;
  93. }
  94. /**
  95. * Return amount of payments already done
  96. *
  97. * @param int $multicurrency Return multicurrency_amount instead of amount
  98. * @return int Amount of payment already done, <0 if KO
  99. */
  100. function getSommePaiement($multicurrency=0)
  101. {
  102. $table='paiement_facture';
  103. $field='fk_facture';
  104. if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier')
  105. {
  106. $table='paiementfourn_facturefourn';
  107. $field='fk_facturefourn';
  108. }
  109. $sql = 'SELECT sum(amount) as amount, sum(multicurrency_amount) as multicurrency_amount';
  110. $sql.= ' FROM '.MAIN_DB_PREFIX.$table;
  111. $sql.= ' WHERE '.$field.' = '.$this->id;
  112. dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
  113. $resql=$this->db->query($sql);
  114. if ($resql)
  115. {
  116. $obj = $this->db->fetch_object($resql);
  117. $this->db->free($resql);
  118. if ($multicurrency) return $obj->multicurrency_amount;
  119. else return $obj->amount;
  120. }
  121. else
  122. {
  123. $this->error=$this->db->lasterror();
  124. return -1;
  125. }
  126. }
  127. /**
  128. * Return amount (with tax) of all deposits invoices used by invoice.
  129. * Should always be empty, except if option FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is on (not recommended).
  130. *
  131. * @param int $multicurrency Return multicurrency_amount instead of amount
  132. * @return int <0 if KO, Sum of deposits amount otherwise
  133. */
  134. function getSumDepositsUsed($multicurrency=0)
  135. {
  136. if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier')
  137. {
  138. // TODO
  139. return 0;
  140. }
  141. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  142. $discountstatic=new DiscountAbsolute($this->db);
  143. $result=$discountstatic->getSumDepositsUsed($this, $multicurrency);
  144. if ($result >= 0)
  145. {
  146. return $result;
  147. }
  148. else
  149. {
  150. $this->error=$discountstatic->error;
  151. return -1;
  152. }
  153. }
  154. /**
  155. * Return amount (with tax) of all credit notes and deposits invoices used by invoice
  156. *
  157. * @param int $multicurrency Return multicurrency_amount instead of amount
  158. * @return int <0 if KO, Sum of credit notes and deposits amount otherwise
  159. */
  160. function getSumCreditNotesUsed($multicurrency=0)
  161. {
  162. if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier')
  163. {
  164. // TODO
  165. return 0;
  166. }
  167. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  168. $discountstatic=new DiscountAbsolute($this->db);
  169. $result=$discountstatic->getSumCreditNotesUsed($this, $multicurrency);
  170. if ($result >= 0)
  171. {
  172. return $result;
  173. }
  174. else
  175. {
  176. $this->error=$discountstatic->error;
  177. return -1;
  178. }
  179. }
  180. /**
  181. * Renvoie tableau des ids de facture avoir issus de la facture
  182. *
  183. * @return array Tableau d'id de factures avoirs
  184. */
  185. function getListIdAvoirFromInvoice()
  186. {
  187. $idarray=array();
  188. $sql = 'SELECT rowid';
  189. $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
  190. $sql.= ' WHERE fk_facture_source = '.$this->id;
  191. $sql.= ' AND type = 2';
  192. $resql=$this->db->query($sql);
  193. if ($resql)
  194. {
  195. $num = $this->db->num_rows($resql);
  196. $i = 0;
  197. while ($i < $num)
  198. {
  199. $row = $this->db->fetch_row($resql);
  200. $idarray[]=$row[0];
  201. $i++;
  202. }
  203. }
  204. else
  205. {
  206. dol_print_error($this->db);
  207. }
  208. return $idarray;
  209. }
  210. /**
  211. * Renvoie l'id de la facture qui la remplace
  212. *
  213. * @param string $option filtre sur statut ('', 'validated', ...)
  214. * @return int <0 si KO, 0 si aucune facture ne remplace, id facture sinon
  215. */
  216. function getIdReplacingInvoice($option='')
  217. {
  218. $sql = 'SELECT rowid';
  219. $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
  220. $sql.= ' WHERE fk_facture_source = '.$this->id;
  221. $sql.= ' AND type < 2';
  222. if ($option == 'validated') $sql.= ' AND fk_statut = 1';
  223. // PROTECTION BAD DATA
  224. // Au cas ou base corrompue et qu'il y a une facture de remplacement validee
  225. // et une autre non, on donne priorite a la validee.
  226. // Ne devrait pas arriver (sauf si acces concurrentiel et que 2 personnes
  227. // ont cree en meme temps une facture de remplacement pour la meme facture)
  228. $sql.= ' ORDER BY fk_statut DESC';
  229. $resql=$this->db->query($sql);
  230. if ($resql)
  231. {
  232. $obj = $this->db->fetch_object($resql);
  233. if ($obj)
  234. {
  235. // Si il y en a
  236. return $obj->rowid;
  237. }
  238. else
  239. {
  240. // Si aucune facture ne remplace
  241. return 0;
  242. }
  243. }
  244. else
  245. {
  246. return -1;
  247. }
  248. }
  249. /**
  250. * Return label of type of invoice
  251. *
  252. * @return string Label of type of invoice
  253. */
  254. function getLibType()
  255. {
  256. global $langs;
  257. if ($this->type == CommonInvoice::TYPE_STANDARD) return $langs->trans("InvoiceStandard");
  258. if ($this->type == CommonInvoice::TYPE_REPLACEMENT) return $langs->trans("InvoiceReplacement");
  259. if ($this->type == CommonInvoice::TYPE_CREDIT_NOTE) return $langs->trans("InvoiceAvoir");
  260. if ($this->type == CommonInvoice::TYPE_DEPOSIT) return $langs->trans("InvoiceDeposit");
  261. if ($this->type == CommonInvoice::TYPE_PROFORMA) return $langs->trans("InvoiceProForma"); // Not used.
  262. if ($this->type == CommonInvoice::TYPE_SITUATION) return $langs->trans("InvoiceSituation");
  263. return $langs->trans("Unknown");
  264. }
  265. /**
  266. * Return label of object status
  267. *
  268. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
  269. * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
  270. * @return string Label
  271. */
  272. function getLibStatut($mode=0,$alreadypaid=-1)
  273. {
  274. return $this->LibStatut($this->paye,$this->statut,$mode,$alreadypaid,$this->type);
  275. }
  276. /**
  277. * Renvoi le libelle d'un statut donne
  278. *
  279. * @param int $paye Status field paye
  280. * @param int $status Id status
  281. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=long label + picto
  282. * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
  283. * @param int $type Type invoice
  284. * @return string Libelle du statut
  285. */
  286. function LibStatut($paye,$status,$mode=0,$alreadypaid=-1,$type=0)
  287. {
  288. global $langs;
  289. $langs->load('bills');
  290. //print "$paye,$status,$mode,$alreadypaid,$type";
  291. if ($mode == 0)
  292. {
  293. $prefix='';
  294. if (! $paye)
  295. {
  296. if ($status == 0) return $langs->trans('Bill'.$prefix.'StatusDraft');
  297. if (($status == 3 || $status == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusClosedUnpaid');
  298. if (($status == 3 || $status == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially');
  299. if ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid');
  300. return $langs->trans('Bill'.$prefix.'StatusStarted');
  301. }
  302. else
  303. {
  304. if ($type == self::TYPE_CREDIT_NOTE) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); // credit note
  305. elseif ($type == self::TYPE_DEPOSIT) return $langs->trans('Bill'.$prefix.'StatusConverted'); // deposit invoice
  306. else return $langs->trans('Bill'.$prefix.'StatusPaid');
  307. }
  308. }
  309. if ($mode == 1)
  310. {
  311. $prefix='Short';
  312. if (! $paye)
  313. {
  314. if ($status == 0) return $langs->trans('Bill'.$prefix.'StatusDraft');
  315. if (($status == 3 || $status == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled');
  316. if (($status == 3 || $status == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially');
  317. if ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid');
  318. return $langs->trans('Bill'.$prefix.'StatusStarted');
  319. }
  320. else
  321. {
  322. if ($type == self::TYPE_CREDIT_NOTE) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted');
  323. elseif ($type == self::TYPE_DEPOSIT) return $langs->trans('Bill'.$prefix.'StatusConverted');
  324. else return $langs->trans('Bill'.$prefix.'StatusPaid');
  325. }
  326. }
  327. if ($mode == 2)
  328. {
  329. $prefix='Short';
  330. if (! $paye)
  331. {
  332. if ($status == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('Bill'.$prefix.'StatusDraft');
  333. if (($status == 3 || $status == 2) && $alreadypaid <= 0) return img_picto($langs->trans('StatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled');
  334. if (($status == 3 || $status == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7').' '.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially');
  335. if ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1').' '.$langs->trans('Bill'.$prefix.'StatusNotPaid');
  336. return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('Bill'.$prefix.'StatusStarted');
  337. }
  338. else
  339. {
  340. if ($type == self::TYPE_CREDIT_NOTE) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted');
  341. elseif ($type == self::TYPE_DEPOSIT) return img_picto($langs->trans('BillStatusConverted'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusConverted');
  342. else return img_picto($langs->trans('BillStatusPaid'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusPaid');
  343. }
  344. }
  345. if ($mode == 3)
  346. {
  347. $prefix='Short';
  348. if (! $paye)
  349. {
  350. if ($status == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0');
  351. if (($status == 3 || $status == 2) && $alreadypaid <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5');
  352. if (($status == 3 || $status == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7');
  353. if ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1');
  354. return img_picto($langs->trans('BillStatusStarted'),'statut3');
  355. }
  356. else
  357. {
  358. if ($type == self::TYPE_CREDIT_NOTE) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6');
  359. elseif ($type == self::TYPE_DEPOSIT) return img_picto($langs->trans('BillStatusConverted'),'statut6');
  360. else return img_picto($langs->trans('BillStatusPaid'),'statut6');
  361. }
  362. }
  363. if ($mode == 4)
  364. {
  365. $prefix='';
  366. if (! $paye)
  367. {
  368. if ($status == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('BillStatusDraft');
  369. if (($status == 3 || $status == 2) && $alreadypaid <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled');
  370. if (($status == 3 || $status == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7').' '.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially');
  371. if ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1').' '.$langs->trans('BillStatusNotPaid');
  372. return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('BillStatusStarted');
  373. }
  374. else
  375. {
  376. if ($type == self::TYPE_CREDIT_NOTE) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6').' '.$langs->trans('BillStatusPaidBackOrConverted');
  377. elseif ($type == self::TYPE_DEPOSIT) return img_picto($langs->trans('BillStatusConverted'),'statut6').' '.$langs->trans('BillStatusConverted');
  378. else return img_picto($langs->trans('BillStatusPaid'),'statut6').' '.$langs->trans('BillStatusPaid');
  379. }
  380. }
  381. if ($mode == 5 || $mode == 6)
  382. {
  383. $prefix='';
  384. if ($mode == 5) $prefix='Short';
  385. if (! $paye)
  386. {
  387. if ($status == 0) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusDraft').' </span>'.img_picto($langs->trans('BillStatusDraft'),'statut0');
  388. if (($status == 3 || $status == 2) && $alreadypaid <= 0) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusCanceled').' </span>'.img_picto($langs->trans('BillStatusCanceled'),'statut5');
  389. if (($status == 3 || $status == 2) && $alreadypaid > 0) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially').' </span>'.img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7');
  390. if ($alreadypaid <= 0)
  391. {
  392. if ($type == self::TYPE_CREDIT_NOTE) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusNotRefunded').' </span>'.img_picto($langs->trans('StatusNotRefunded'),'statut1');
  393. return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusNotPaid').' </span>'.img_picto($langs->trans('BillStatusNotPaid'),'statut1');
  394. }
  395. return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusStarted').' </span>'.img_picto($langs->trans('BillStatusStarted'),'statut3');
  396. }
  397. else
  398. {
  399. if ($type == self::TYPE_CREDIT_NOTE) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted').' </span>'.img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6');
  400. elseif ($type == self::TYPE_DEPOSIT) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusConverted').' </span>'.img_picto($langs->trans('BillStatusConverted'),'statut6');
  401. else return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusPaid').' </span>'.img_picto($langs->trans('BillStatusPaid'),'statut6');
  402. }
  403. }
  404. }
  405. /**
  406. * Renvoi une date limite de reglement de facture en fonction des
  407. * conditions de reglements de la facture et date de facturation
  408. *
  409. * @param integer $cond_reglement Condition of payment (code or id) to use. If 0, we use current condition.
  410. * @return date Date limite de reglement si ok, <0 si ko
  411. */
  412. function calculate_date_lim_reglement($cond_reglement=0)
  413. {
  414. if (! $cond_reglement) $cond_reglement=$this->cond_reglement_code;
  415. if (! $cond_reglement) $cond_reglement=$this->cond_reglement_id;
  416. $cdr_nbjour=0; $cdr_type=0; $cdr_decalage=0;
  417. $sqltemp = 'SELECT c.type_cdr,c.nbjour,c.decalage';
  418. $sqltemp.= ' FROM '.MAIN_DB_PREFIX.'c_payment_term as c';
  419. if (is_numeric($cond_reglement)) $sqltemp.= " WHERE c.rowid=".$cond_reglement;
  420. else $sqltemp.= " WHERE c.code='".$this->db->escape($cond_reglement)."'";
  421. dol_syslog(get_class($this).'::calculate_date_lim_reglement', LOG_DEBUG);
  422. $resqltemp=$this->db->query($sqltemp);
  423. if ($resqltemp)
  424. {
  425. if ($this->db->num_rows($resqltemp))
  426. {
  427. $obj = $this->db->fetch_object($resqltemp);
  428. $cdr_nbjour = $obj->nbjour;
  429. $cdr_type = $obj->type_cdr;
  430. $cdr_decalage = $obj->decalage;
  431. }
  432. }
  433. else
  434. {
  435. $this->error=$this->db->error();
  436. return -1;
  437. }
  438. $this->db->free($resqltemp);
  439. /* Definition de la date limite */
  440. // 1 : ajout du nombre de jours
  441. $datelim = $this->date + ($cdr_nbjour * 3600 * 24);
  442. // 2 : application de la regle "fin de mois"
  443. if ($cdr_type == 1)
  444. {
  445. $mois=date('m', $datelim);
  446. $annee=date('Y', $datelim);
  447. if ($mois == 12)
  448. {
  449. $mois = 1;
  450. $annee += 1;
  451. }
  452. else
  453. {
  454. $mois += 1;
  455. }
  456. // On se deplace au debut du mois suivant, et on retire un jour
  457. $datelim=dol_mktime(12,0,0,$mois,1,$annee);
  458. $datelim -= (3600 * 24);
  459. }
  460. elseif($cdr_type == 2 && !empty($cdr_nbjour)) // Application de la règle, le N du mois courant ou suivant
  461. {
  462. $date_piece = dol_mktime(0,0,0,date('m', $this->date),date('d', $this->date),date('Y', $this->date)); // Sans les heures minutes et secondes
  463. $date_lim_current = dol_mktime(0,0,0,date('m', $this->date),$cdr_nbjour,date('Y', $this->date)); // Sans les heures minutes et secondes
  464. $date_lim_next = strtotime(date('Y-m-d', $date_lim_current).' +1month');
  465. $diff = $date_piece - $date_lim_current;
  466. if($diff < 0) $datelim = $date_lim_current;
  467. else $datelim = $date_lim_next;
  468. }
  469. // 3 : application du decalage
  470. $datelim += ($cdr_decalage * 3600 * 24);
  471. return $datelim;
  472. }
  473. }
  474. require_once DOL_DOCUMENT_ROOT .'/core/class/commonobjectline.class.php';
  475. /**
  476. * Parent class of all other business classes for details of elements (invoices, contracts, proposals, orders, ...)
  477. */
  478. abstract class CommonInvoiceLine extends CommonObjectLine
  479. {
  480. /**
  481. * Quantity
  482. * @var int
  483. */
  484. public $qty;
  485. /**
  486. * Unit price before taxes
  487. * @var float
  488. */
  489. public $subprice;
  490. /**
  491. * Type of the product. 0 for product 1 for service
  492. * @var int
  493. */
  494. public $product_type = 0;
  495. /**
  496. * Id of corresponding product
  497. * @var int
  498. */
  499. public $fk_product;
  500. /**
  501. * VAT code
  502. * @var string
  503. */
  504. public $vat_src_code;
  505. /**
  506. * VAT %
  507. * @var float
  508. */
  509. public $tva_tx;
  510. /**
  511. * Local tax 1 %
  512. * @var float
  513. */
  514. public $localtax1_tx;
  515. /**
  516. * Local tax 2 %
  517. * @var float
  518. */
  519. public $localtax2_tx;
  520. /**
  521. * Percent of discount
  522. * @var float
  523. */
  524. public $remise_percent;
  525. /**
  526. * Total amount before taxes
  527. * @var float
  528. */
  529. public $total_ht;
  530. /**
  531. * Total VAT amount
  532. * @var float
  533. */
  534. public $total_tva;
  535. /**
  536. * Total local tax 1 amount
  537. * @var float
  538. */
  539. public $total_localtax1;
  540. /**
  541. * Total local tax 2 amount
  542. * @var float
  543. */
  544. public $total_localtax2;
  545. /**
  546. * Total amount with taxes
  547. * @var float
  548. */
  549. public $total_ttc;
  550. /**
  551. * Liste d'options cumulables:
  552. * Bit 0: 0 si TVA normal - 1 si TVA NPR
  553. * Bit 1: 0 si ligne normal - 1 si bit discount (link to line into llx_remise_except)
  554. * @var int
  555. */
  556. public $info_bits = 0;
  557. /**
  558. * Constructor
  559. *
  560. * @param DoliDB $db Database handler
  561. */
  562. public function __construct(DoliDB $db)
  563. {
  564. $this->db = $db;
  565. }
  566. }