30 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
42 public $element =
'payment_supplier';
47 public $table_element =
'paiementfourn';
52 public $picto =
'payment';
73 public $id_prelevement;
78 public $num_prelevement;
99 public function fetch($id, $ref =
'', $fk_bank =
'')
103 $sql =
'SELECT p.rowid, p.ref, p.entity, p.datep as dp, p.amount, p.statut, p.fk_bank, p.multicurrency_amount,';
104 $sql .=
' c.code as payment_code, c.libelle as payment_type,';
105 $sql .=
' p.num_paiement as num_payment, p.note, b.fk_account, p.fk_paiement';
106 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
107 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
108 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
109 $sql .=
' WHERE p.entity IN ('.getEntity(
'facture_fourn').
')';
111 $sql .=
' AND p.rowid = '.((int) $id);
113 $sql .=
" AND p.ref = '".$this->db->escape($ref).
"'";
114 } elseif ($fk_bank > 0) {
115 $sql .=
' AND p.fk_bank = '.((int) $fk_bank);
123 $obj = $this->
db->fetch_object(
$resql);
125 $this->
id = $obj->rowid;
126 $this->
ref = $obj->ref;
127 $this->entity = $obj->entity;
128 $this->date = $this->
db->jdate($obj->dp);
129 $this->datepaye = $this->
db->jdate($obj->dp);
130 $this->num_payment = $obj->num_payment;
131 $this->numero = $obj->num_payment;
132 $this->bank_account = $obj->fk_account;
133 $this->fk_account = $obj->fk_account;
134 $this->bank_line = $obj->fk_bank;
135 $this->montant = $obj->amount;
136 $this->amount = $obj->amount;
137 $this->multicurrency_amount = $obj->multicurrency_amount;
138 $this->note = $obj->note;
139 $this->note_private = $obj->note;
140 $this->type_code = $obj->payment_code;
141 $this->type_label = $obj->payment_type;
142 $this->fk_paiement = $obj->fk_paiement;
143 $this->statut = $obj->statut;
165 public function create($user, $closepaidinvoices = 0, $thirdparty =
null)
167 global $langs, $conf;
176 $totalamount_converted = 0;
177 $atleastonepaymentnotnull = 0;
179 if ($way ==
'dolibarr') {
180 $amounts = &$this->amounts;
181 $amounts_to_update = &$this->multicurrency_amounts;
183 $amounts = &$this->multicurrency_amounts;
184 $amounts_to_update = &$this->amounts;
187 $currencyofpayment =
'';
189 foreach ($amounts as $key => $value) {
194 $value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value ? $value : 0, $way,
'facture_fourn');
196 if ($value_converted ===
false) {
198 $this->error =
'FailedToFoundTheConversionRateForInvoice';
201 if (empty($currencyofpayment)) {
202 $currencyofpayment = $this->multicurrency_code[$key];
204 if ($currencyofpayment != $this->multicurrency_code[$key]) {
206 $this->error =
'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
210 $totalamount_converted += $value_converted;
211 $amounts_to_update[$key] =
price2num($value_converted,
'MT');
214 $amounts[$key] = $newvalue;
215 $totalamount += $newvalue;
216 if (!empty($newvalue)) {
217 $atleastonepaymentnotnull++;
221 if (!empty($currencyofpayment)) {
224 $bankaccount->fetch($this->fk_account);
225 $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
226 if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
227 $langs->load(
"errors");
228 $this->error = $langs->trans(
'ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
235 $totalamount_converted =
price2num($totalamount_converted);
237 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
241 if ($totalamount <> 0) {
242 $ref = $this->
getNextNumRef(is_object($thirdparty) ? $thirdparty :
'');
244 if ($way ==
'dolibarr') {
246 $mtotal = $totalamount_converted;
248 $total = $totalamount_converted;
249 $mtotal = $totalamount;
252 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn (';
253 $sql .=
'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
254 $sql .=
" VALUES ('".$this->db->escape($ref).
"', ".((int) $conf->entity).
", '".$this->
db->idate($now).
"',";
255 $sql .=
" '".$this->db->idate($this->datepaye).
"', ".((
float)
$total).
", ".((
float) $mtotal).
", ".((int) $this->paiementid).
", '".$this->
db->escape($this->num_payment).
"', '".$this->
db->escape($this->note_private).
"', ".((int) $user->id).
", 0)";
259 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
'paiementfourn');
262 foreach ($this->amounts as $key => $amount) {
264 if (is_numeric($amount) && $amount <> 0) {
266 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount)';
267 $sql .=
" VALUES (".((int) $facid).
", ".((int) $this->
id).
", ".((
float) $amount).
', '.((
float) $this->multicurrency_amounts[$key]).
')';
271 $invoice->fetch($facid);
274 if ($closepaidinvoices) {
275 $paiement = $invoice->getSommePaiement();
276 $creditnotes=$invoice->getSumCreditNotesUsed();
278 $deposits=$invoice->getSumDepositsUsed();
280 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
281 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
282 if ($remaintopay == 0) {
285 $amount_ht = $amount_tva = $amount_ttc = array();
286 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
289 require_once DOL_DOCUMENT_ROOT .
'/core/class/discount.class.php';
291 $discount->fetch(
'', 0, $invoice->id);
292 if (empty($discount->id)) {
293 $discount->discount_type = 1;
294 $discount->description =
'(DEPOSIT)';
295 $discount->fk_soc = $invoice->socid;
296 $discount->fk_invoice_supplier_source = $invoice->id;
300 foreach ($invoice->lines as $line) {
301 if ($line->total_ht != 0) {
302 $amount_ht[$line->tva_tx] += $line->total_ht;
303 $amount_tva[$line->tva_tx] += $line->total_tva;
304 $amount_ttc[$line->tva_tx] += $line->total_ttc;
305 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
306 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
307 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
312 foreach ($amount_ht as $tva_tx => $xxx) {
313 $discount->amount_ht = abs($amount_ht[$tva_tx]);
314 $discount->amount_tva = abs($amount_tva[$tva_tx]);
315 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
316 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
317 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
318 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
319 $discount->tva_tx = abs($tva_tx);
321 $result = $discount->create($user);
337 $result = $invoice->setPaid($user,
'',
'');
339 $this->error = $invoice->error;
344 dol_syslog(
"Remain to pay for invoice ".$facid.
" not null. We do nothing.");
349 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
351 $outputlangs = $langs;
353 $newlang = $invoice->thirdparty->default_lang;
355 if (!empty($newlang)) {
357 $outputlangs->setDefaultLang($newlang);
359 $ret = $invoice->fetch($facid);
360 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs);
367 $this->error = $this->
db->lasterror();
371 dol_syslog(get_class($this).
'::Create Amount line '.$key.
' not a number. We discard it.');
377 $result = $this->
call_trigger(
'PAYMENT_SUPPLIER_CREATE', $user);
384 $this->error = $this->
db->lasterror();
388 $this->error =
"ErrorTotalIsNull";
389 dol_syslog(
'PaiementFourn::Create Error '.$this->error, LOG_ERR);
393 if ($totalamount <> 0 && $error == 0) {
396 $this->multicurrency_amount = $mtotal;
398 dol_syslog(
'PaiementFourn::Create Ok Total = '.$this->amount.
', Total currency = '.$this->multicurrency_amount);
401 $this->
db->rollback();
415 public function delete($notrigger = 0)
417 global $conf, $user, $langs;
419 $bank_line_id = $this->bank_line;
426 if (is_array($billsarray)) {
427 if (count($billsarray)) {
428 $this->error =
"ErrorCantDeletePaymentSharedWithPayedInvoice";
429 $this->
db->rollback();
433 $this->
db->rollback();
441 $accline->fetch($bank_line_id);
442 if ($accline->rappro) {
443 $this->error =
"ErrorCantDeletePaymentReconciliated";
444 $this->
db->rollback();
450 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
451 $sql .=
' WHERE fk_paiementfourn = '.((int) $this->
id);
454 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'paiementfourn';
455 $sql .=
" WHERE rowid = ".((int) $this->
id);
456 $result = $this->
db->query($sql);
458 $this->error = $this->
db->error();
459 $this->
db->rollback();
466 $result = $accline->fetch($bank_line_id);
468 $result = $accline->delete($user);
471 $this->error = $accline->error;
472 $this->
db->rollback();
479 $result = $this->
call_trigger(
'PAYMENT_SUPPLIER_DELETE', $user);
481 $this->
db->rollback();
490 $this->error = $this->
db->error;
491 $this->
db->rollback();
504 $sql =
'SELECT c.rowid, datec, fk_user_author as fk_user_creat, tms';
505 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as c';
506 $sql .=
' WHERE c.rowid = '.((int) $id);
512 $obj = $this->
db->fetch_object(
$resql);
513 $this->
id = $obj->rowid;
515 if ($obj->fk_user_creat) {
516 $cuser =
new User($this->
db);
517 $cuser->fetch($obj->fk_user_creat);
518 $this->user_creation = $cuser;
520 if ($obj->fk_user_modif) {
521 $muser =
new User($this->
db);
522 $muser->fetch($obj->fk_user_modif);
523 $this->user_modification = $muser;
525 $this->date_creation = $this->
db->jdate($obj->datec);
526 $this->date_modification = $this->
db->jdate($obj->tms);
542 $sql =
'SELECT fk_facturefourn';
543 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'facture_fourn as f';
544 $sql .=
' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.((int) $this->
id);
546 $sql .=
" AND ".$filter;
549 dol_syslog(get_class($this).
'::getBillsArray', LOG_DEBUG);
554 $billsarray = array();
557 $obj = $this->
db->fetch_object(
$resql);
558 $billsarray[$i] = $obj->fk_facturefourn;
564 $this->error = $this->
db->error();
565 dol_syslog(get_class($this).
'::getBillsArray Error '.$this->error);
578 return $this->
LibStatut($this->statut, $mode);
594 $langs->load(
'compta');
644 public function getNomUrl($withpicto = 0, $option =
'', $mode =
'withlistofinvoices', $notooltip = 0, $morecss =
'')
646 global $langs, $conf, $hookmanager;
648 if (!empty($conf->dol_no_mouse_hover)) {
656 if (preg_match(
'/^\((.*)\)$/i', $text, $reg)) {
658 if ($reg[1] ==
'paiement') {
661 $text = $langs->trans($reg[1]);
664 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Payment").
'</u><br>';
665 $label .=
'<strong>'.$langs->trans(
"Ref").
':</strong> '.$text;
666 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
667 if ($dateofpayment) {
668 $label .=
'<br><strong>'.$langs->trans(
"Date").
':</strong> '.
dol_print_date($dateofpayment,
'dayhour',
'tzuser');
671 $label .=
'<br><strong>'.$langs->trans(
"Amount").
':</strong> '.
price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
675 if (empty($notooltip)) {
676 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
677 $label = $langs->trans(
"Payment");
678 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
680 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
681 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
683 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
686 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/paiement/card.php?id='.$this->
id.
'"';
687 $linkstart .= $linkclose.
'>';
690 $result .= $linkstart;
692 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
694 if ($withpicto != 2) {
695 $result .= $this->ref;
700 $hookmanager->initHooks(array($this->element .
'dao'));
701 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
702 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
704 $result = $hookmanager->resPrint;
706 $result .= $hookmanager->resPrint;
721 global $user, $langs, $conf;
725 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
729 $this->
ref =
'SPECIMEN';
733 $this->datepaye = $nownotime;
746 global $conf, $db, $langs;
747 $langs->load(
"bills");
750 if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) {
751 $conf->global->SUPPLIER_PAYMENT_ADDON =
'mod_supplier_payment_bronan';
752 } elseif ($conf->global->SUPPLIER_PAYMENT_ADDON ==
'brodator') {
753 $conf->global->SUPPLIER_PAYMENT_ADDON =
'mod_supplier_payment_brodator';
754 } elseif ($conf->global->SUPPLIER_PAYMENT_ADDON ==
'bronan') {
755 $conf->global->SUPPLIER_PAYMENT_ADDON =
'mod_supplier_payment_bronan';
758 if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON)) {
761 $file = $conf->global->SUPPLIER_PAYMENT_ADDON.
".php";
762 $classname = $conf->global->SUPPLIER_PAYMENT_ADDON;
765 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
767 foreach ($dirmodels as $reldir) {
768 $dir =
dol_buildpath($reldir.
"core/modules/supplier_payment/");
771 if (is_file($dir.$file) && is_readable($dir.$file)) {
772 $mybool |= include_once $dir.$file;
777 if ($mybool ===
false) {
778 $file = $conf->global->SUPPLIER_PAYMENT_ADDON.
".php";
779 $classname =
"mod_supplier_payment_".$conf->global->SUPPLIER_PAYMENT_ADDON;
780 $classname = preg_replace(
'/\-.*$/',
'', $classname);
782 foreach ($conf->file->dol_document_root as $dirroot) {
783 $dir = $dirroot.
"/core/modules/supplier_payment/";
786 if (is_file($dir.$file) && is_readable($dir.$file)) {
787 $mybool |= include_once $dir.$file;
792 if ($mybool ===
false) {
797 $obj =
new $classname();
799 $numref = $obj->getNextValue($soc, $this);
805 if ($mode !=
'last' && !$numref) {
812 $langs->load(
"errors");
813 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Supplier"));
829 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
831 global $conf, $user, $langs;
833 $langs->load(
"suppliers");
836 if (empty($modele)) {
837 if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF)) {
838 $modele = $conf->global->SUPPLIER_PAYMENT_ADDON_PDF;
844 if (empty($modele)) {
847 $modelpath =
"core/modules/supplier_payment/doc/";
849 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
866 foreach ($this->multicurrency_amounts as $value) {
867 if (!empty($value)) {
888 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
890 if (empty($force_thirdparty_id)) {
892 if (!empty($billsarray)) {
894 if ($supplier_invoice->fetch($billsarray[0]) > 0) {
895 $force_thirdparty_id = $supplier_invoice->fk_soc;
900 return parent::fetch_thirdparty($force_thirdparty_id);
Class to manage bank accounts.
Class to manage bank transaction lines.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage absolute discounts.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
Class to manage payments for supplier invoices.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
getNextNumRef($soc, $mode='next')
Return next reference of supplier invoice not already used (or last reference) according to numbering...
initAsSpecimen($option='')
Initialise an instance with random values.
getLibStatut($mode=0)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
__construct($db)
Constructor.
info($id)
Information on object.
create($user, $closepaidinvoices=0, $thirdparty=null)
Create payment in database.
getBillsArray($filter='')
Return list of supplier invoices the payment point to.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template model.
getNomUrl($withpicto=0, $option='', $mode='withlistofinvoices', $notooltip=0, $morecss='')
Return clicable name (with picto eventually)
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id into this->thirdparty.
getWay()
get the right way of payment
fetch($id, $ref='', $fk_bank='')
Load payment object.
Class to manage payments of customer invoices.
Class to manage translations.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
div float
Buy price without taxes.
$conf db
API class for accounts.