diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index e3350dbe14a..51760bd047e 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -367,6 +367,8 @@ abstract class CommonDocGenerator global $conf; $sumpayed=$sumdeposit=$sumcreditnote=''; + $already_payed_all=0; + $remain_to_pay=0; if ($object->element == 'facture') { $invoice_source=new Facture($this->db); @@ -377,6 +379,8 @@ abstract class CommonDocGenerator $sumpayed = $object->getSommePaiement(); $sumdeposit = $object->getSumDepositsUsed(); $sumcreditnote = $object->getSumCreditNotesUsed(); + $already_payed_all=$sumpayed + $sumdeposit + $sumcreditnote; + $remain_to_pay=$sumpayed - $sumdeposit - $sumcreditnote; } $date = ($object->element == 'contrat' ? $object->date_contrat : $object->date); @@ -438,12 +442,12 @@ abstract class CommonDocGenerator $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs), $array_key.'_already_creditnote'=>price2num($sumcreditnote), - $array_key.'_already_payed_all_locale'=>price(price2num($sumpayed + $sumdeposit + $sumcreditnote, 'MT'), 0, $outputlangs), - $array_key.'_already_payed_all'=> price2num(($sumpayed + $sumdeposit + $sumcreditnote), 'MT'), + $array_key.'_already_payed_all_locale'=>price(price2num($already_payed_all, 'MT'), 0, $outputlangs), + $array_key.'_already_payed_all'=> price2num($already_payed_all, 'MT'), // Remain to pay with all know infrmation (except open direct debit requests) - $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT'), 0, $outputlangs), - $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT') + $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $remain_to_pay, 'MT'), 0, $outputlangs), + $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $remain_to_pay, 'MT') ); if (method_exists($object, 'getTotalDiscount')) { diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 85abdf2b004..3973931ffd7 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -152,6 +152,7 @@ class DoliDBPgsql extends DoliDB */ static function convertSQLFromMysql($line,$type='auto',$unescapeslashquot=false) { + global $conf; // Removed empty line if this is a comment line for SVN tagging if (preg_match('/^--\s\$Id/i',$line)) { return ''; @@ -311,7 +312,14 @@ class DoliDBPgsql extends DoliDB } // To have postgresql case sensitive - $line=str_replace(' LIKE \'',' ILIKE \'',$line); + $count_like=0; + $line=str_replace(' LIKE \'',' ILIKE \'',$line,$count_like); + if (!empty($conf->global->PSQL_USE_UNACCENT) && $count_like > 0) + { + // @see https://docs.postgresql.fr/11/unaccent.html : 'unaccent()' function must be installed before + $line=preg_replace('/\s+(\(+\s*)([a-zA-Z0-9\-\_\.]+) ILIKE /', ' \1unaccent(\2) ILIKE ', $line); + } + $line=str_replace(' LIKE BINARY \'',' LIKE \'',$line); // Replace INSERT IGNORE into INSERT diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index ab2ffb3bd2a..37812647caa 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -739,7 +739,7 @@ class pdf_crabe extends ModelePDFFactures // Affiche zone versements if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) { - $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs); + $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter); } // Pied de page @@ -785,9 +785,10 @@ class pdf_crabe extends ModelePDFFactures * @param Object $object Object invoice * @param int $posy Position y in PDF * @param Translate $outputlangs Object langs for output + * @param int $heightforfooter height for footer * @return int <0 if KO, >0 if OK */ - function _tableau_versements(&$pdf, $object, $posy, $outputlangs) + function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter) { // phpcs:enable global $conf; @@ -795,6 +796,7 @@ class pdf_crabe extends ModelePDFFactures $sign=1; if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1; + $current_page = $pdf->getPage(); $tab3_posx = 120; $tab3_top = $posy + 8; $tab3_width = 80; @@ -806,26 +808,7 @@ class pdf_crabe extends ModelePDFFactures $default_font_size = pdf_getPDFFontSize($outputlangs); - $title=$outputlangs->transnoentities("PaymentsAlreadyDone"); - if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone"); - - $pdf->SetFont('','', $default_font_size - 3); - $pdf->SetXY($tab3_posx, $tab3_top - 4); - $pdf->MultiCell(60, 3, $title, 0, 'L', 0); - - $pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top); - - $pdf->SetFont('','', $default_font_size - 4); - $pdf->SetXY($tab3_posx, $tab3_top); - $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0); - $pdf->SetXY($tab3_posx+21, $tab3_top); - $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0); - $pdf->SetXY($tab3_posx+40, $tab3_top); - $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0); - $pdf->SetXY($tab3_posx+58, $tab3_top); - $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0); - - $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height); + $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height); $y=0; @@ -847,6 +830,17 @@ class pdf_crabe extends ModelePDFFactures while ($i < $num) { $y+=3; + if ($tab3_top+$y >= $this->page_hauteur-$heightforfooter) + { + $y=0; + $current_page++; + $pdf->AddPage('','',true); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + $pdf->setPage($current_page); + $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top+$y-3, $tab3_width, $tab3_height); + } + $obj = $this->db->fetch_object($resql); if ($obj->type == 2) $text=$outputlangs->transnoentities("CreditNote"); @@ -893,6 +887,17 @@ class pdf_crabe extends ModelePDFFactures $i=0; while ($i < $num) { $y+=3; + if ($tab3_top+$y >= $this->page_hauteur-$heightforfooter) + { + $y=0; + $current_page++; + $pdf->AddPage('','',true); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + $pdf->setPage($current_page); + $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top+$y-3, $tab3_width, $tab3_height); + } + $row = $this->db->fetch_object($resql); $pdf->SetXY($tab3_posx, $tab3_top+$y); @@ -918,6 +923,39 @@ class pdf_crabe extends ModelePDFFactures } } + /** + * @param PDF $pdf Object PDF + * @param Facture $object Object invoice + * @param Translate $outputlangs Object langs for output + * @param int $default_font_size Font size + * @param int $tab3_posx pos x + * @param int $tab3_top pos y + * @param int $tab3_width width + * @param int $tab3_height height + */ + function _tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height) + { + $title=$outputlangs->transnoentities("PaymentsAlreadyDone"); + if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone"); + + $pdf->SetFont('','', $default_font_size - 3); + $pdf->SetXY($tab3_posx, $tab3_top - 4); + $pdf->MultiCell(60, 3, $title, 0, 'L', 0); + + $pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top); + + $pdf->SetFont('','', $default_font_size - 4); + $pdf->SetXY($tab3_posx, $tab3_top); + $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0); + $pdf->SetXY($tab3_posx+21, $tab3_top); + $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0); + $pdf->SetXY($tab3_posx+40, $tab3_top); + $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0); + $pdf->SetXY($tab3_posx+58, $tab3_top); + $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0); + + $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height); + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps /** diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 381d3fbef86..05bfc3b106d 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -73,9 +73,13 @@ $coldisplay=-1; // We remove first td + fk_product > 0) { ?> + fk_parent_line > 0) echo img_picto('', 'rightarrow'); + ?> product_type==1) echo img_object($langs->trans('ShowService'),'service'); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index bfc356d945b..e68eecbca81 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -601,7 +601,7 @@ class Expedition extends CommonObject $this->db->free($result); - if ($this->statut == 0) $this->brouillon = 1; + if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; // Tracking url $this->GetUrlTrackingStatus($obj->tracking_number); @@ -841,7 +841,7 @@ class Expedition extends CommonObject if (! $error) { $this->ref = $numref; - $this->statut = 1; + $this->statut = self::STATUS_VALIDATED; } if (! $error) @@ -876,7 +876,7 @@ class Expedition extends CommonObject if ($conf->livraison_bon->enabled) { - if ($this->statut == 1 || $this->statut == 2) + if ($this->statut == self::STATUS_VALIDATED || $this->statut == self::STATUS_CLOSED) { // Expedition validee include_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php'; @@ -1184,7 +1184,7 @@ class Expedition extends CommonObject } // Stock control - if (! $error && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0) + if (! $error && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) { require_once DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"; @@ -1734,7 +1734,7 @@ class Expedition extends CommonObject $this->id=0; $this->ref = 'SPECIMEN'; $this->specimen=1; - $this->statut = 1; + $this->statut = self::STATUS_VALIDATED; $this->livraison_id = 0; $this->date = $now; $this->date_creation = $now; @@ -2119,6 +2119,7 @@ class Expedition extends CommonObject } else { + $this->statut = self::STATUS_VALIDATED; $this->db->rollback(); return -1; } @@ -2144,7 +2145,7 @@ class Expedition extends CommonObject $resql=$this->db->query($sql); if ($resql) { - $this->statut=2; + $this->statut=self::STATUS_CLOSED; $this->billed=1; // Call trigger @@ -2163,6 +2164,8 @@ class Expedition extends CommonObject } else { + $this->statut=self::STATUS_VALIDATED; + $this->billed=0; $this->db->rollback(); return -1; } @@ -2187,13 +2190,15 @@ class Expedition extends CommonObject $this->db->begin(); + $oldbilled=$this->billed; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; $resql=$this->db->query($sql); if ($resql) { - $this->statut=1; + $this->statut=self::STATUS_VALIDATED; $this->billed=0; // If stock increment is done on closing @@ -2290,6 +2295,8 @@ class Expedition extends CommonObject } else { + $this->statut=self::STATUS_CLOSED; + $this->billed=$oldbilled; $this->db->rollback(); return -1; } diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index 4a1b004fed7..82cb0314de9 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -619,7 +619,10 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print '