';
+ /**
+ * Function to load data from a SQL pointer into properties of current object $this
+ *
+ * @param stdClass $record Contain data of object from database
+ * @return void
+ */
+ public function setVarsFromFetchObj(&$record)
+ {
+ if (is_object($this->object)) {
+ $this->object->setVarsFromFetchObj($record);
- if ($currentPage > 1) {
- $html .= '
';
+ // specific to get invoice status (depends on payment)
+ if ($this->element == 'invoice') {
+ $discount = new DiscountAbsolute($this->db);
+
+ // Store company
+ $idCompany = (int) $this->object->socid;
+ if (!isset($this->companyStaticList[$idCompany])) {
+ $companyStatic = new Societe($this->db);
+ $companyStatic->fetch($idCompany);
+ $this->companyStaticList[$idCompany] = $companyStatic;
+ }
+ $companyStatic = $this->companyStaticList[$idCompany];
+
+ // paid sum
+ $payment = $this->object->getSommePaiement();
+ $totalcreditnotes = $this->object->getSumCreditNotesUsed();
+ $totaldeposits = $this->object->getSumDepositsUsed();
+
+ // remain to pay
+ $totalpay = $payment + $totalcreditnotes + $totaldeposits;
+ $remaintopay = price2num($this->object->total_ttc - $totalpay);
+ if ($this->object->status == Facture::STATUS_CLOSED && $this->object->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment
+ $remaintopay = 0;
+ }
+ if ($this->object->type == Facture::TYPE_CREDIT_NOTE && $this->object->paye == 1) {
+ // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal
+ $remaincreditnote = $discount->getAvailableDiscounts($companyStatic, '', 'rc.fk_facture_source=' . $this->object->id);
+ $remaintopay = -$remaincreditnote;
+ }
+
+ $record->invoice_payment = $payment;
+ $record->invoice_remaintopay = $remaintopay;
+ }
+ }
+ }
+
+ /**
+ * Print value for list
+ *
+ * @param string $field_key Field key
+ * @param array $field_spec Field specification
+ * @param stdClass $record Contain data of object from database
+ * @param int $i Index line (0, 1, 2, ...)
+ * @param array $totalarray Array for total line
+ * @return string HTML input
+ */
+ public function printValue($field_key, $field_spec, &$record, $i, &$totalarray)
+ {
+ global $conf;
+
+ $out = '';
+ if (is_object($this->object)) {
+ $out = $this->controller->listPrintValueBefore($field_key, $field_spec, $record);
+ if (empty($out)) {
+ if ($field_key == 'status' || $field_key == 'fk_statut') {
+ if ($this->element == 'invoice') {
+ // specific to get invoice status (depends on payment)
+ $out = $this->object->getLibStatut(5, $record->invoice_payment);
+ } else {
+ $out = $this->object->getLibStatut(5);
+ }
+ } elseif ($field_key == 'rowid') {
+ $out = $this->form->showOutputFieldForObject($this->object, $field_spec, $field_key, (string) $this->object->id, '');
+ } elseif ($field_key == 'remain_to_pay') {
+ if ($this->element == 'invoice') {
+ $out = $this->form->showOutputFieldForObject($this->object, $this->arrayfields['remain_to_pay'], 'remain_to_pay', $record->invoice_remaintopay, '');
+ }
+ } elseif ($field_key == 'download_link') {
+ $element = $this->element;
+ $filename = dol_sanitizeFileName($this->object->ref);
+ $filedir = $conf->{$element}->multidir_output[$this->object->entity] . '/' . dol_sanitizeFileName($this->object->ref);
+ $out = $this->form->getDocumentsLink($element, $filename, $filedir);
+ } elseif ($field_key == 'signature_link') {
+ if ($this->object->fk_statut == Propal::STATUS_VALIDATED) {
+ $out = $this->form->getSignatureLink('proposal', $this->object);
+ }
+ } else {
+ $out = $this->form->showOutputFieldForObject($this->object, $field_spec, $field_key, $this->object->$field_key, '');
+ }
+ }
+
+ $out = $this->controller->listPrintValueAfter($field_key, $field_spec, $record, $out);
}
- $maxPaginItem = min($nbPages, 5);
- $minPageNum = max(1, $currentPage - 3);
- $maxPageNum = min($nbPages, $currentPage + 3);
+ return $out;
+ }
- if ($minPageNum > 1) {
- $html .= '