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';
90 public function fetch($id, $ref =
'', $fk_bank =
'')
94 $sql =
'SELECT p.rowid, p.ref, p.entity, p.datep as dp, p.amount, p.statut, p.fk_bank, p.multicurrency_amount,';
95 $sql .=
' c.code as payment_code, c.libelle as payment_type,';
96 $sql .=
' p.num_paiement as num_payment, p.note, b.fk_account';
97 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as p';
98 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
99 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
100 $sql .=
' WHERE p.entity IN ('.getEntity(
'facture_fourn').
')';
102 $sql .=
' AND p.rowid = '.$id;
104 $sql .=
' AND p.rowid = '.$ref;
106 $sql .=
' AND p.fk_bank = '.$fk_bank;
115 $obj = $this->
db->fetch_object(
$resql);
117 $this->
id = $obj->rowid;
118 $this->ref = $obj->ref;
119 $this->entity = $obj->entity;
120 $this->date = $this->
db->jdate($obj->dp);
121 $this->datepaye = $this->
db->jdate($obj->dp);
122 $this->num_payment = $obj->num_payment;
123 $this->numero = $obj->num_payment;
124 $this->bank_account = $obj->fk_account;
125 $this->fk_account = $obj->fk_account;
126 $this->bank_line = $obj->fk_bank;
127 $this->montant = $obj->amount;
128 $this->amount = $obj->amount;
129 $this->multicurrency_amount = $obj->multicurrency_amount;
130 $this->
note = $obj->note;
131 $this->note_private = $obj->note;
132 $this->type_code = $obj->payment_code;
133 $this->type_label = $obj->payment_type;
134 $this->
statut = $obj->statut;
156 public function create($user, $closepaidinvoices = 0, $thirdparty = null)
158 global $langs, $conf;
165 $totalamount_converted = 0;
167 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
169 if ($way ==
'dolibarr')
171 $amounts = &$this->amounts;
172 $amounts_to_update = &$this->multicurrency_amounts;
174 $amounts = &$this->multicurrency_amounts;
175 $amounts_to_update = &$this->amounts;
178 foreach ($amounts as $key => $value)
180 $value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value ? $value : 0, $way,
'facture_fourn');
181 $totalamount_converted += $value_converted;
182 $amounts_to_update[$key] =
price2num($value_converted,
'MT');
185 $amounts[$key] = $newvalue;
186 $totalamount += $newvalue;
189 $totalamount_converted =
price2num($totalamount_converted);
193 if ($totalamount <> 0)
195 $ref = $this->
getNextNumRef(is_object($thirdparty) ? $thirdparty :
'');
198 if ($way ==
'dolibarr')
201 $mtotal = $totalamount_converted;
203 $total = $totalamount_converted;
204 $mtotal = $totalamount;
207 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn (';
208 $sql .=
'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
209 $sql .=
" VALUES ('".$this->db->escape($ref).
"', ".$conf->entity.
", '".$this->
db->idate($now).
"',";
210 $sql .=
" '".$this->db->idate($this->datepaye).
"', '".
$total.
"', '".$mtotal.
"', ".$this->paiementid.
", '".$this->
db->escape($this->num_payment).
"', '".$this->
db->escape($this->note_private).
"', ".$user->id.
", 0)";
215 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
'paiementfourn');
218 foreach ($this->amounts as $key => $amount)
221 if (is_numeric($amount) && $amount <> 0)
224 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount)';
225 $sql .=
' VALUES ('.$facid.
','.$this->
id.
',\''.$amount.
'\', \
''.$this->multicurrency_amounts[$key].
'\')
';
226 $resql = $this->db->query($sql);
229 $invoice = new FactureFournisseur($this->db);
230 $invoice->fetch($facid);
232 // If we want to closed paid invoices
233 if ($closepaidinvoices)
235 $paiement = $invoice->getSommePaiement();
236 //$creditnotes=$invoice->getSumCreditNotesUsed();
238 //$deposits=$invoice->getSumDepositsUsed();
240 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT
');
241 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT
');
242 if ($remaintopay == 0)
244 $result = $invoice->set_paid($user, '', '');
245 } else dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing.");
248 // Regenerate documents of invoices
249 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
252 $outputlangs = $langs;
253 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang;
254 if (!empty($newlang)) {
255 $outputlangs = new Translate("", $conf);
256 $outputlangs->setDefaultLang($newlang);
258 $ret = $invoice->fetch($facid); // Reload to get new records
259 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs);
261 setEventMessages($invoice->error, $invoice->errors, 'errors
');
266 $this->error = $this->db->lasterror();
270 dol_syslog(get_class($this).'::Create Amount line
'.$key.' not a number. We discard it.
');
277 $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE
', $user);
278 if ($result < 0) $error++;
282 $this->error = $this->db->lasterror();
286 $this->error = "ErrorTotalIsNull";
287 dol_syslog('PaiementFourn::Create Error
'.$this->error, LOG_ERR);
291 if ($totalamount <> 0 && $error == 0) // On accepte les montants negatifs
293 $this->amount = $total;
294 $this->total = $total;
295 $this->multicurrency_amount = $mtotal;
297 dol_syslog('PaiementFourn::Create Ok Total =
'.$this->total);
300 $this->db->rollback();
314 public function delete($notrigger = 0)
316 global $conf, $user, $langs;
318 $bank_line_id = $this->bank_line;
322 // Verifier si paiement porte pas sur une facture a l'etat payee
325 if (is_array($billsarray))
327 if (count($billsarray))
329 $this->error =
"ErrorCantDeletePaymentSharedWithPayedInvoice";
330 $this->
db->rollback();
334 $this->
db->rollback();
343 $accline->fetch($bank_line_id);
344 if ($accline->rappro)
346 $this->error =
"ErrorCantDeletePaymentReconciliated";
347 $this->
db->rollback();
353 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
354 $sql .=
' WHERE fk_paiementfourn = '.$this->id;
358 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'paiementfourn';
359 $sql .=
' WHERE rowid = '.$this->id;
360 $result = $this->
db->query($sql);
363 $this->error = $this->
db->error();
364 $this->
db->rollback();
372 $result = $accline->fetch($bank_line_id);
375 $result = $accline->delete($user);
379 $this->error = $accline->error;
380 $this->
db->rollback();
388 $result = $this->
call_trigger(
'PAYMENT_SUPPLIER_DELETE', $user);
391 $this->
db->rollback();
400 $this->error = $this->
db->error;
401 $this->
db->rollback();
414 $sql =
'SELECT c.rowid, datec, fk_user_author as fk_user_creat, tms';
415 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn as c';
416 $sql .=
' WHERE c.rowid = '.$id;
424 $obj = $this->
db->fetch_object(
$resql);
425 $this->
id = $obj->rowid;
427 if ($obj->fk_user_creat)
429 $cuser =
new User($this->
db);
430 $cuser->fetch($obj->fk_user_creat);
431 $this->user_creation = $cuser;
433 if ($obj->fk_user_modif)
435 $muser =
new User($this->
db);
436 $muser->fetch($obj->fk_user_modif);
437 $this->user_modification = $muser;
439 $this->date_creation = $this->
db->jdate($obj->datec);
440 $this->date_modification = $this->
db->jdate($obj->tms);
456 $sql =
'SELECT fk_facturefourn';
457 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.
'facture_fourn as f';
458 $sql .=
' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.$this->id;
459 if ($filter) $sql .=
' AND '.$filter;
461 dol_syslog(get_class($this).
'::getBillsArray', LOG_DEBUG);
467 $billsarray = array();
471 $obj = $this->
db->fetch_object(
$resql);
472 $billsarray[$i] = $obj->fk_facturefourn;
478 $this->error = $this->
db->error();
479 dol_syslog(get_class($this).
'::getBillsArray Error '.$this->error);
508 $langs->load(
'compta');
557 public function getNomUrl($withpicto = 0, $option =
'', $mode =
'withlistofinvoices', $notooltip = 0)
565 if (preg_match(
'/^\((.*)\)$/i', $text, $reg)) {
567 if ($reg[1] ==
'paiement') $reg[1] =
'Payment';
568 $text = $langs->trans($reg[1]);
571 $label =
'<u>'.$langs->trans(
"Payment").
'</u><br>';
572 $label .=
'<strong>'.$langs->trans(
"Ref").
':</strong> '.$text;
573 if ($this->datepaye ? $this->datepaye : $this->date) $label .=
'<br><strong>'.$langs->trans(
"Date").
':</strong> '.
dol_print_date($this->datepaye ? $this->datepaye : $this->date,
'dayhour');
575 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/fourn/paiement/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
578 $result .= $linkstart;
579 if ($withpicto) $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);
580 if ($withpicto != 2) $result .= $this->ref;
596 global $user, $langs, $conf;
600 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
604 $this->ref =
'SPECIMEN';
608 $this->datepaye = $nownotime;
621 global $conf, $db, $langs;
622 $langs->load(
"bills");
625 if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) $conf->global->SUPPLIER_PAYMENT_ADDON =
'mod_supplier_payment_bronan';
626 elseif ($conf->global->SUPPLIER_PAYMENT_ADDON ==
'brodator') $conf->global->SUPPLIER_PAYMENT_ADDON =
'mod_supplier_payment_brodator';
627 elseif ($conf->global->SUPPLIER_PAYMENT_ADDON ==
'bronan') $conf->global->SUPPLIER_PAYMENT_ADDON =
'mod_supplier_payment_bronan';
629 if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON))
633 $file = $conf->global->SUPPLIER_PAYMENT_ADDON.
".php";
634 $classname = $conf->global->SUPPLIER_PAYMENT_ADDON;
637 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
639 foreach ($dirmodels as $reldir) {
640 $dir =
dol_buildpath($reldir.
"core/modules/supplier_payment/");
643 if (is_file($dir.$file) && is_readable($dir.$file))
645 $mybool |= include_once $dir.$file;
650 if ($mybool ===
false) {
651 $file = $conf->global->SUPPLIER_PAYMENT_ADDON.
".php";
652 $classname =
"mod_supplier_payment_".$conf->global->SUPPLIER_PAYMENT_ADDON;
653 $classname = preg_replace(
'/\-.*$/',
'', $classname);
655 foreach ($conf->file->dol_document_root as $dirroot) {
656 $dir = $dirroot.
"/core/modules/supplier_payment/";
659 if (is_file($dir.$file) && is_readable($dir.$file)) {
660 $mybool |= include_once $dir.$file;
665 if ($mybool ===
false) {
670 $obj =
new $classname();
672 $numref = $obj->getNextValue($soc, $this);
678 if ($mode !=
'last' && !$numref) {
685 $langs->load(
"errors");
686 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Supplier"));
702 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
704 global $conf, $user, $langs;
706 $langs->load(
"suppliers");
711 if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF))
713 $modele = $conf->global->SUPPLIER_PAYMENT_ADDON_PDF;
723 $modelpath =
"core/modules/supplier_payment/doc/";
725 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
741 if (!empty($conf->multicurrency->enabled))
743 foreach ($this->multicurrency_amounts as $value)
767 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
769 if (empty($force_thirdparty_id))
772 if (!empty($billsarray))
775 if ($supplier_invoice->fetch($billsarray[0]) > 0)
777 $force_thirdparty_id = $supplier_invoice->fk_soc;
782 return parent::fetch_thirdparty($force_thirdparty_id);
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
initAsSpecimen($option= '')
Initialise an instance with random values.
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...
getWay()
get the right way of payment
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
Class to manage bank transaction lines.
Class to manage suppliers invoices.
__construct($db)
Constructor.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$conf db
API class for accounts.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage payments of customer invoices.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
getNomUrl($withpicto=0, $option= '', $mode= 'withlistofinvoices', $notooltip=0)
Return clicable name (with picto eventually)
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getLibStatut($mode=0)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) ...
getBillsArray($filter= '')
Return list of supplier invoices the payment point to.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id into this->thirdparty.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
info($id)
Information on object.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getNextNumRef($soc, $mode= 'next')
Return next reference of supplier invoice not already used (or last reference) according to numbering...
fetch($id, $ref= '', $fk_bank= '')
Load payment object.
Class to manage payments for supplier invoices.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template model.
create($user, $closepaidinvoices=0, $thirdparty=null)
Create payment in database.
if(!empty($search_group)) natural_search(array("g.nom"g note
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...