226 public function fetch($rowid, $fk_facture_source = 0, $fk_invoice_supplier_source = 0)
229 if (!$rowid && !$fk_facture_source && !$fk_invoice_supplier_source) {
230 $this->error =
'ErrorBadParameters';
234 $sql =
"SELECT sr.rowid, sr.fk_soc, sr.discount_type,";
235 $sql .=
" sr.fk_user,";
236 $sql .=
" sr.amount_ht, sr.amount_tva, sr.amount_localtax1, sr.amount_localtax2, sr.amount_ttc, sr.tva_tx, sr.localtax1_tx, sr.localtax1_type, sr.localtax2_tx, sr.localtax2_type, sr.vat_src_code,";
237 $sql .=
" sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,";
238 $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,";
239 $sql .=
" sr.datec,";
240 $sql .=
" f.ref as ref_facture_source, f.type as type_facture_source,";
241 $sql .=
" fsup.ref as ref_invoice_supplier_source, fsup.type as type_invoice_supplier_source";
242 $sql .=
" FROM ".$this->db->prefix().
"societe_remise_except as sr";
243 $sql .=
" LEFT JOIN ".$this->db->prefix().
"facture as f ON sr.fk_facture_source = f.rowid";
244 $sql .=
" LEFT JOIN ".$this->db->prefix().
"facture_fourn as fsup ON sr.fk_invoice_supplier_source = fsup.rowid";
245 $sql .=
" WHERE sr.entity IN (".getEntity(
'invoice').
")";
247 $sql .=
" AND sr.rowid = ".((int) $rowid);
249 if ($fk_facture_source) {
250 $sql .=
" AND sr.fk_facture_source = ".((int) $fk_facture_source);
252 if ($fk_invoice_supplier_source) {
253 $sql .=
" AND sr.fk_invoice_supplier_source = ".((int) $fk_invoice_supplier_source);
256 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
257 $resql = $this->db->query($sql);
259 if ($this->db->num_rows($resql)) {
260 $obj = $this->db->fetch_object($resql);
262 $this->
id = $obj->rowid;
263 $this->fk_soc = $obj->fk_soc;
264 $this->socid = $obj->fk_soc;
265 $this->discount_type = $obj->discount_type;
267 $this->total_ht = $obj->amount_ht;
268 $this->total_tva = $obj->amount_tva;
269 $this->total_localtax1 = $obj->amount_localtax1;
270 $this->total_localtax2 = $obj->amount_localtax2;
271 $this->total_ttc = $obj->amount_ttc;
273 $this->amount_ht = $this->total_ht;
274 $this->amount_tva = $this->total_tva;
275 $this->amount_ttc = $this->total_ttc;
277 $this->multicurrency_total_ht = $this->multicurrency_subprice = $obj->multicurrency_amount_ht;
278 $this->multicurrency_total_tva = $obj->multicurrency_amount_tva;
279 $this->multicurrency_total_ttc = $obj->multicurrency_amount_ttc;
281 $this->multicurrency_amount_ht = $this->multicurrency_total_ht;
282 $this->multicurrency_amount_tva = $this->multicurrency_total_tva;
283 $this->multicurrency_amount_ttc = $this->multicurrency_total_ttc;
285 $this->tva_tx = $obj->tva_tx;
286 $this->localtax1_tx = $obj->localtax1_tx;
287 $this->localtax1_type = $obj->localtax1_type;
288 $this->localtax2_tx = $obj->localtax2_tx;
289 $this->localtax2_type = $obj->localtax2_type;
290 $this->vat_src_code = $obj->vat_src_code;
292 $this->fk_user = $obj->fk_user;
293 $this->fk_facture_line = $obj->fk_facture_line;
294 $this->fk_facture = $obj->fk_facture;
295 $this->fk_facture_source = $obj->fk_facture_source;
296 $this->ref_facture_source = $obj->ref_facture_source;
297 $this->type_facture_source = $obj->type_facture_source;
298 $this->fk_invoice_supplier_line = $obj->fk_invoice_supplier_line;
299 $this->fk_invoice_supplier = $obj->fk_invoice_supplier;
300 $this->fk_invoice_supplier_source = $obj->fk_invoice_supplier_source;
301 $this->ref_invoice_supplier_source = $obj->ref_invoice_supplier_source;
302 $this->type_invoice_supplier_source = $obj->type_invoice_supplier_source;
304 $this->datec = $this->db->jdate($obj->datec);
306 $this->db->free($resql);
309 $this->db->free($resql);
313 $this->error = $this->db->error();
330 $this->amount_ht =
price2num($this->amount_ht);
331 $this->amount_tva =
price2num($this->amount_tva);
332 $this->amount_ttc =
price2num($this->amount_ttc);
334 $this->tva_tx =
price2num($this->tva_tx);
335 $this->localtax1_tx =
price2num($this->localtax1_tx);
336 $this->localtax1_type =
price2num($this->localtax1_type);
337 $this->localtax2_tx =
price2num($this->localtax2_tx);
338 $this->localtax2_type =
price2num($this->localtax2_type);
340 $this->multicurrency_amount_ht =
price2num($this->multicurrency_amount_ht);
341 $this->multicurrency_amount_tva =
price2num($this->multicurrency_amount_tva);
342 $this->multicurrency_amount_ttc =
price2num($this->multicurrency_amount_ttc);
344 if (empty($this->multicurrency_amount_ht)) {
345 $this->multicurrency_amount_ht = 0;
347 if (empty($this->multicurrency_amount_tva)) {
348 $this->multicurrency_amount_tva = 0;
350 if (empty($this->multicurrency_amount_ttc)) {
351 $this->multicurrency_amount_ttc = 0;
353 if (empty($this->tva_tx)) {
356 if (empty($this->localtax1_tx)) {
357 $this->localtax1_tx = 0;
358 $this->localtax1_type = 0;
360 if (empty($this->localtax2_tx)) {
361 $this->localtax2_tx = 0;
362 $this->localtax2_type = 0;
367 $this->error =
'BadValueForPropertyDescriptionOfDiscount';
368 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
373 if (!($userid > 0)) {
374 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
375 $tmpinvoice =
new Facture($this->db);
376 $tmpinvoice->fetch($this->fk_facture_source);
377 $userid = $tmpinvoice->user_creation_id;
381 $sql =
"INSERT INTO ".$this->db->prefix().
"societe_remise_except";
382 $sql .=
" (entity, datec, fk_soc, discount_type, fk_user, description,";
383 $sql .=
" amount_ht, amount_tva, amount_localtax1, amount_localtax2, amount_ttc, tva_tx, localtax1_tx, localtax1_type, localtax2_tx, localtax2_type, vat_src_code,";
384 $sql .=
" multicurrency_amount_ht, multicurrency_amount_tva, multicurrency_amount_ttc,";
385 $sql .=
" fk_facture_source, fk_invoice_supplier_source, multicurrency_code, multicurrency_tx";
387 $sql .=
" VALUES (".$conf->entity.
", '".$this->db->idate($this->datec !=
'' ? $this->datec :
dol_now()).
"', ".((
int) $this->socid).
", ".(empty($this->discount_type) ? 0 : intval($this->discount_type)).
", ".((
int) $userid).
", '".$this->db->escape($this->description).
"',";
388 $sql .=
" ".price2num($this->amount_ht).
", ".
price2num($this->amount_tva).
", ";
389 $sql .=
" ".($this->total_localtax1 ?
price2num($this->total_localtax1) : 0).
", ".($this->total_localtax2 ?
price2num($this->total_localtax2) : 0).
", ".
price2num($this->amount_ttc).
", ".
price2num($this->tva_tx).
",";
390 $sql .=
" ".price2num($this->localtax1_tx).
", ".
price2num($this->localtax1_type).
", ";
391 $sql .=
" ".($this->localtax2_tx ?
price2num($this->localtax2_tx) : 0).
", ".($this->localtax2_type ?
price2num($this->localtax2_type) : 0).
", '".$this->db->escape($this->vat_src_code).
"',";
392 $sql .=
" ".price2num($this->multicurrency_amount_ht).
", ".
price2num($this->multicurrency_amount_tva).
", ";
393 $sql .=
" ".price2num($this->multicurrency_amount_ttc).
", ";
394 $sql .=
" ".($this->fk_facture_source ? ((int) $this->fk_facture_source) :
"null").
",";
395 $sql .=
" ".($this->fk_invoice_supplier_source ? ((int) $this->fk_invoice_supplier_source) :
"null").
",";
396 $sql .=
" ".($this->multicurrency_code ?
"'".$this->db->escape($this->multicurrency_code).
"'" :
"null").
",";
397 $sql .=
" ".($this->multicurrency_tx ?
price2num($this->multicurrency_tx) :
"null");
400 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
401 $resql = $this->db->query($sql);
403 $this->
id = $this->db->last_insert_id($this->db->prefix().
"societe_remise_except");
406 $this->error = $this->db->lasterror().
' - sql='.$sql;
418 public function delete($user)
421 if ($this->fk_facture_source) {
422 $sql =
"SELECT COUNT(rowid) as nb";
423 $sql .=
" FROM ".$this->db->prefix().
"societe_remise_except";
424 $sql .=
" WHERE (fk_facture_line IS NOT NULL";
425 $sql .=
" OR fk_facture IS NOT NULL)";
426 $sql .=
" AND fk_facture_source = ".((int) $this->fk_facture_source);
429 dol_syslog(get_class($this).
"::delete Check if we can remove discount", LOG_DEBUG);
430 $resql = $this->db->query($sql);
432 $obj = $this->db->fetch_object($resql);
434 $this->error =
'ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved';
444 if ($this->fk_invoice_supplier_source) {
445 $sql =
"SELECT COUNT(rowid) as nb";
446 $sql .=
" FROM ".$this->db->prefix().
"societe_remise_except";
447 $sql .=
" WHERE (fk_invoice_supplier_line IS NOT NULL";
448 $sql .=
" OR fk_invoice_supplier IS NOT NULL)";
449 $sql .=
" AND fk_invoice_supplier_source = ".((int) $this->fk_invoice_supplier_source);
452 dol_syslog(get_class($this).
"::delete Check if we can remove discount", LOG_DEBUG);
453 $resql = $this->db->query($sql);
455 $obj = $this->db->fetch_object($resql);
457 $this->error =
'ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved';
469 $sql =
"DELETE FROM ".$this->db->prefix().
"societe_remise_except ";
470 if ($this->fk_facture_source) {
471 $sql .=
" WHERE fk_facture_source = ".((int) $this->fk_facture_source);
472 } elseif ($this->fk_invoice_supplier_source) {
473 $sql .=
" WHERE fk_invoice_supplier_source = ".((int) $this->fk_invoice_supplier_source);
475 $sql .=
" WHERE rowid = ".((int) $this->
id);
477 $sql .=
" AND (fk_facture_line IS NULL";
478 $sql .=
" AND fk_facture IS NULL)";
479 $sql .=
" AND (fk_invoice_supplier_line IS NULL";
480 $sql .=
" AND fk_invoice_supplier IS NULL)";
482 dol_syslog(get_class($this).
"::delete Delete discount", LOG_DEBUG);
484 require_once DOL_DOCUMENT_ROOT.
'/core/class/commoninvoice.class.php';
485 $result = $this->db->query($sql);
488 if ($this->fk_facture_source) {
489 $sql =
"UPDATE ".$this->db->prefix().
"facture";
490 $sql .=
" set paye=0, fk_statut=1";
493 dol_syslog(get_class($this).
"::delete Update credit note or deposit invoice statut", LOG_DEBUG);
494 $result = $this->db->query($sql);
499 $this->error = $this->db->lasterror();
500 $this->db->rollback();
503 } elseif ($this->fk_invoice_supplier_source) {
504 $sql =
"UPDATE ".$this->db->prefix().
"facture_fourn";
505 $sql .=
" set paye=0, fk_statut=1";
508 dol_syslog(get_class($this).
"::delete Update credit note or deposit invoice statut", LOG_DEBUG);
509 $result = $this->db->query($sql);
514 $this->error = $this->db->lasterror();
515 $this->db->rollback();
523 $this->error = $this->db->lasterror();
524 $this->db->rollback();
548 if (!$rowidline && !$rowidinvoice) {
549 $this->error =
'ErrorBadParameters';
552 if ($rowidline && $rowidinvoice) {
553 $this->error =
'ErrorBadParameters';
557 $sql =
"UPDATE ".$this->db->prefix().
"societe_remise_except";
558 if (!empty($this->discount_type)) {
560 $sql .=
" SET fk_invoice_supplier_line = ".((int) $rowidline);
563 $sql .=
" SET fk_invoice_supplier = ".((int) $rowidinvoice);
567 $sql .=
" SET fk_facture_line = ".((int) $rowidline);
570 $sql .=
" SET fk_facture = ".((int) $rowidinvoice);
573 $sql .=
" WHERE rowid = ".((int) $this->
id);
575 dol_syslog(get_class($this).
"::link_to_invoice", LOG_DEBUG);
576 $resql = $this->db->query($sql);
578 if (!empty($this->discount_type)) {
579 $this->fk_invoice_supplier_line = $rowidline;
580 $this->fk_invoice_supplier = $rowidinvoice;
582 $this->fk_facture_line = $rowidline;
583 $this->fk_facture = $rowidinvoice;
591 $sourceinvoiceid = 0;
593 if (!empty($this->discount_type)) {
594 $sourcetype =
'invoice_supplier';
595 $targettype =
'invoice_supplier';
596 $sourceinvoiceid = (int) $this->fk_invoice_supplier_source;
598 $sourcetype =
'facture';
599 $targettype =
'facture';
600 $sourceinvoiceid = (int) $this->fk_facture_source;
603 if ($sourceinvoiceid > 0 && $sourceinvoiceid !== (
int) $rowidinvoice) {
604 $sqlcheck =
"SELECT 1";
605 $sqlcheck .=
" FROM ".$this->db->prefix().
"element_element";
606 $sqlcheck .=
" WHERE fk_source = ".((int) $sourceinvoiceid);
607 $sqlcheck .=
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
608 $sqlcheck .=
" AND fk_target = ".((int) $rowidinvoice);
609 $sqlcheck .=
" AND targettype = '".$this->db->escape($targettype).
"'";
610 $sqlcheck .= $this->db->plimit(1);
612 $rescheck = $this->db->query($sqlcheck);
613 if ($rescheck && $this->db->num_rows($rescheck) === 0) {
614 $sqladd =
"INSERT INTO ".$this->db->prefix().
"element_element (fk_source, sourcetype, fk_target, targettype)";
615 $sqladd .=
" VALUES (".((int) $sourceinvoiceid).
", '".$this->db->escape($sourcetype).
"', ".((int) $rowidinvoice).
", '".$this->db->escape($targettype).
"')";
616 $this->db->query($sqladd);
623 $result = $this->call_trigger(
'DISCOUNT_MODIFY', $user);
631 $this->error = $this->db->error();
688 public function getAvailableDiscounts($company =
null, $user =
null, $filter =
'', $maxvalue = 0, $discount_type = 0, $multicurrency = 0)
690 global
$conf, $hookmanager;
692 dol_syslog(get_class($this).
"::getAvailableDiscounts discount_type=".$discount_type, LOG_DEBUG);
695 'company' => $company,
698 'maxvalue' => $maxvalue,
699 'discount_type' => $discount_type,
700 'multicurrency' => $multicurrency
703 $reshook = $hookmanager->executeHooks(
'getAvailableDiscounts', $parameters);
704 if (empty($reshook)) {
705 $sql =
"SELECT SUM(rc.amount_ttc) as amount, SUM(rc.multicurrency_amount_ttc) as multicurrency_amount";
706 $sql .=
" FROM ".$this->db->prefix().
"societe_remise_except as rc";
707 $sql .=
" WHERE rc.entity = ".$conf->entity;
708 $sql .=
" AND rc.discount_type=".((int) $discount_type);
709 if (!empty($discount_type)) {
710 $sql .=
" AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
712 $sql .=
" AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)";
714 if (is_object($company)) {
715 $sql .=
" AND rc.fk_soc = ".((int) $company->id);
717 if (is_object($user)) {
718 $sql .=
" AND rc.fk_user = ".((int) $user->id);
721 $sql .=
" AND (".$filter.
")";
724 $sql .=
' AND rc.amount_ttc <= '.((float)
price2num($maxvalue));
727 $sql = $hookmanager->resArray[
'sql'];
730 $resql = $this->db->query($sql);
732 $obj = $this->db->fetch_object($resql);
738 if ($multicurrency) {
739 return $obj->multicurrency_amount;
757 dol_syslog(get_class($this).
"::getSumDepositsUsed", LOG_DEBUG);
759 if ($invoice->element ==
'facture' || $invoice->element ==
'invoice') {
760 $sql =
"SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount";
761 $sql .=
" FROM ".$this->db->prefix().
"societe_remise_except as rc, ".$this->db->prefix().
"facture as f";
762 $sql .=
" WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = ".((int) $invoice->id);
763 $sql .=
" AND f.type = ". (int) $invoice::TYPE_DEPOSIT;
764 } elseif ($invoice->element ==
'invoice_supplier') {
765 $sql =
"SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount";
766 $sql .=
" FROM ".$this->db->prefix().
"societe_remise_except as rc, ".$this->db->prefix().
"facture_fourn as f";
767 $sql .=
" WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = ".((int) $invoice->id);
768 $sql .=
" AND f.type = ". (int) $invoice::TYPE_DEPOSIT;
770 $this->error = get_class($this).
"::getSumDepositsUsed was called with a bad object as a first parameter";
775 $resql = $this->db->query($sql);
777 $obj = $this->db->fetch_object($resql);
778 if ($multicurrency == 1) {
779 return $obj->multicurrency_amount;
784 $this->error = $this->db->lasterror();
798 dol_syslog(get_class($this).
"::getSumCreditNotesUsed", LOG_DEBUG);
800 if ($invoice->element ==
'facture' || $invoice->element ==
'invoice') {
801 $sql =
"SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount";
802 $sql .=
" FROM ".$this->db->prefix().
"societe_remise_except as rc, ".$this->db->prefix().
"facture as f";
803 $sql .=
" WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = ".((int) $invoice->id);
804 $sql .=
" AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.
", ".$invoice::TYPE_CREDIT_NOTE.
", ".$invoice::TYPE_SITUATION).
")";
805 } elseif ($invoice->element ==
'invoice_supplier') {
806 $sql =
"SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount";
807 $sql .=
" FROM ".$this->db->prefix().
"societe_remise_except as rc, ".$this->db->prefix().
"facture_fourn as f";
808 $sql .=
" WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = ".((int) $invoice->id);
809 $sql .=
" AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.
", ".$invoice::TYPE_CREDIT_NOTE).
")";
811 $this->error = get_class($this).
"::getSumCreditNotesUsed was called with a bad object as a first parameter";
813 return 'ErrorBadElementType';
816 $resql = $this->db->query($sql);
818 $obj = $this->db->fetch_object($resql);
819 if ($multicurrency == 1) {
820 return $obj->multicurrency_amount;
825 $this->error = $this->db->lasterror();
826 return 'ErrorBadSQLquery';
875 public function getNomUrl($withpicto = 0, $option =
'invoice')
886 if ($option ==
'invoice') {
887 $facid = !empty($this->discount_type) ? $this->fk_invoice_supplier_source : $this->fk_facture_source;
888 $link = !empty($this->discount_type) ?
'/fourn/facture/card.php' :
'/compta/facture/card.php';
889 $label = $langs->trans(
"ShowSourceInvoice").
': '.$this->ref_facture_source;
890 $link =
'<a href="'.DOL_URL_ROOT.$link.
'?facid='.$facid.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
892 $ref = !empty($this->discount_type) ? $this->ref_invoice_supplier_source : $this->ref_facture_source;
895 if ($option ==
'discount') {
896 $label = $langs->trans(
"Discount");
897 $link =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$this->socid.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
899 $ref = $langs->trans(
"Discount");
905 $result .= ($link.img_object($label, $picto,
'class="classfortooltip"').$linkend);
907 if ($withpicto && $withpicto != 2) {
910 $result .= $link.$ref.$linkend;
946 public function generateFromAmount($amount, $amount_type, $tva_tx, $localtax1_tx, $localtax2_tx, $localtax1_type = 1, $localtax2_type = 1)
948 $localtax1_tx_pct = (float) ($localtax1_tx / 100);
949 $localtax2_tx_pct = (float) ($localtax2_tx / 100);
950 $tva_tx_pct = (float) ($tva_tx / 100);
954 $localtax1_type2 = ((int) $localtax1_type > 0 && (
int) $localtax1_type % 2 == 0 ? 1 : 0);
955 $localtax2_type2 = ((int) $localtax2_type > 0 && (
int) $localtax2_type % 2 == 0 ? 1 : 0);
957 if ($amount_type == 1) {
960 $this->amount_ttc =
price2num($amount,
'MT');
962 if (!$localtax1_type2 && !$localtax2_type2) {
963 $diviseur = 1 + $tva_tx_pct + $localtax1_tx_pct + $localtax2_tx_pct;
964 $this->amount_ht =
price2num((
float) $amount / $diviseur,
'MT');
965 $this->amount_tva =
price2num((
float) $this->amount_ht * $tva_tx_pct,
'MT');
967 $diviseur = 1 + $tva_tx_pct * ($localtax1_tx_pct > 0 ? $localtax1_tx_pct : 1) * ($localtax2_tx_pct > 0 ? $localtax2_tx_pct : 1);
968 $lt1 = 0; $lt2 = 0; $ttc = (float) $this->amount_ttc;
969 if ($localtax2_tx_pct > 0) {
970 $lt2 = $ttc - $ttc / (1 + $localtax2_tx_pct);
972 if ($localtax1_tx_pct > 0) {
973 $lt1 = $ttc - $lt2 - ($ttc - $lt2)/ (1 + $localtax1_tx_pct);
975 $tva = ($ttc - $lt2 - $lt1) - ($ttc - $lt2 - $lt1) / ( 1 + $tva_tx_pct);
976 $this->amount_tva =
price2num($tva,
'MT');
977 $this->total_localtax1 = $lt1;
978 $this->total_localtax2 = $lt2;
979 $this->amount_ht =
price2num((
float) $this->amount_ttc- $this->total_localtax1 - $this->total_localtax2 - (
float) $this->amount_tva,
'MT');
982 $this->multicurrency_amount_ttc =
price2num($amount * (
float) $this->multicurrency_tx,
'MT');
983 $this->multicurrency_amount_ht = $this->amount_ht;
984 $this->multicurrency_amount_tva =
price2num((
float) $this->amount_ht * $tva_tx_pct * (
float) $this->multicurrency_tx,
'MT');
985 } elseif ($amount_type == 0) {
987 $this->amount_ht =
price2num($amount,
'MT');
988 $this->amount_tva =
price2num((
float) $this->amount_ht * $tva_tx_pct,
'MT');
990 $this->multicurrency_amount_ht =
price2num($amount * (
float) $this->multicurrency_tx,
'MT');
991 $this->multicurrency_amount_tva =
price2num(((
float) $amount * $tva_tx_pct) * (
float) $this->multicurrency_tx,
'MT');
994 $this->tva_tx = $tva_tx;
995 $this->localtax1_tx = $localtax1_tx;
996 $this->localtax1_type = $localtax1_type;
997 $this->localtax2_tx = $localtax2_tx;
998 $this->localtax2_type = $localtax2_type;
1000 if ($localtax1_type2 == 0) {
1001 $this->total_localtax1 = (float) $this->amount_ht * $localtax1_tx_pct;
1002 } elseif ($localtax1_type2 == 1) {
1003 $this->total_localtax1 = ((float) $this->amount_ht + (
float) $this->amount_tva) * $localtax1_tx_pct;
1006 if ($localtax2_type2 == 0) {
1007 $this->total_localtax2 = (float) $this->amount_ht * $localtax2_tx_pct;
1008 } elseif ($localtax2_type2 == 1) {
1009 $this->total_localtax2 = ((float) $this->amount_ht + (
float) $this->amount_tva + $this->total_localtax1) * $localtax2_tx_pct;
1012 if (empty($this->amount_ttc)) {
1015 $this->amount_ttc =
price2num((
float) $this->amount_ht + (
float) $this->amount_tva + $this->total_localtax1 + $this->total_localtax2,
'MT');
1016 $this->multicurrency_amount_ttc =
price2num(((
float) $this->amount_ht + (
float) $this->amount_tva + $this->total_localtax1 + $this->total_localtax2) * (
float) $this->multicurrency_tx,
'MT');
1034 $newdiscount1->fk_facture_source = $this->fk_facture_source;
1035 $newdiscount2->fk_facture_source = $this->fk_facture_source;
1036 $newdiscount1->fk_facture = $this->fk_facture;
1037 $newdiscount2->fk_facture = $this->fk_facture;
1038 $newdiscount1->fk_facture_line = $this->fk_facture_line;
1039 $newdiscount2->fk_facture_line = $this->fk_facture_line;
1040 $newdiscount1->fk_invoice_supplier_source = $this->fk_invoice_supplier_source;
1041 $newdiscount2->fk_invoice_supplier_source = $this->fk_invoice_supplier_source;
1042 $newdiscount1->fk_invoice_supplier = $this->fk_invoice_supplier;
1043 $newdiscount2->fk_invoice_supplier = $this->fk_invoice_supplier;
1044 $newdiscount1->fk_invoice_supplier_line = $this->fk_invoice_supplier_line;
1045 $newdiscount2->fk_invoice_supplier_line = $this->fk_invoice_supplier_line;
1047 $newdiscount1->description = $this->description;
1048 $newdiscount2->description = $this->description;
1050 $newdiscount1->description = $this->
description.
' (1)';
1051 $newdiscount2->description = $this->
description.
' (2)';
1053 $newdiscount1->fk_user = $this->fk_user;
1054 $newdiscount2->fk_user = $this->fk_user;
1055 $newdiscount1->fk_soc = $this->fk_soc;
1056 $newdiscount1->socid = $this->socid;
1057 $newdiscount2->fk_soc = $this->fk_soc;
1058 $newdiscount2->socid = $this->socid;
1059 $newdiscount1->discount_type = $this->discount_type;
1060 $newdiscount2->discount_type = $this->discount_type;
1061 $newdiscount1->datec = $this->datec;
1062 $newdiscount2->datec = $this->datec;
1063 $newdiscount1->tva_tx = $this->tva_tx;
1064 $newdiscount2->tva_tx = $this->tva_tx;
1065 $newdiscount1->localtax1_tx = $this->localtax1_tx;
1066 $newdiscount2->localtax1_tx = $this->localtax1_tx;
1067 $newdiscount1->localtax2_tx = $this->localtax2_tx;
1068 $newdiscount2->localtax2_tx = $this->localtax2_tx;
1069 $newdiscount1->vat_src_code = $this->vat_src_code;
1070 $newdiscount2->vat_src_code = $this->vat_src_code;
1072 $newdiscount1->generateFromAmount($amount_ttc1, 1, $newdiscount1->tva_tx, $newdiscount1->localtax1_tx, $newdiscount1->localtax2_tx, $this->localtax1_type, $this->localtax2_type);
1073 $newdiscount2->generateFromAmount($amount_ttc2, 1, $newdiscount1->tva_tx, $newdiscount1->localtax1_tx, $newdiscount1->localtax2_tx, $this->localtax1_type, $this->localtax2_type);
1075 return array($newdiscount1, $newdiscount2);