30 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
42 $langs->loadLangs(array(
'bills',
'banks',
'withdrawals',
'companies'));
46 $socid =
GETPOST(
'socid',
'int');
47 $action =
GETPOST(
'action',
'aZ09');
48 $type =
GETPOST(
'type',
'aZ09');
50 $fieldid = (!empty($ref) ?
'ref' :
'rowid');
52 $socid = $user->socid;
56 if ($type ==
'bank-transfer') {
58 $moreparam =
'&type='.$type;
64 if ($id > 0 || !empty($ref)) {
65 $ret = $object->fetch($id, $ref);
68 $object->fetch_thirdparty();
72 $hookmanager->initHooks(array(
'directdebitcard',
'globalcard'));
74 if ($type ==
'bank-transfer') {
75 $result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture',
'fk_soc', $fieldid, $isdraft);
76 if (empty($user->rights->fournisseur->facture->lire)) {
80 $result =
restrictedArea($user,
'facture', $id,
'',
'',
'fk_soc', $fieldid, $isdraft);
81 if (!$user->rights->facture->lire) {
86 if ($type ==
'bank-transfer') {
87 $usercancreate = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
89 $usercancreate = $user->rights->facture->creer;
97 $parameters = array(
'socid' => $socid);
98 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
103 if (empty($reshook)) {
104 if ($action ==
"new" && $usercancreate) {
105 if ($object->id > 0) {
109 $sourcetype =
'facture';
110 if ($type ==
'bank-transfer') {
111 $sourcetype =
'supplier_invoice';
112 $newtype =
'bank-transfer';
115 $result = $object->demande_prelevement($user,
price2num(
GETPOST(
'withdraw_request_amount',
'alpha')), $newtype, $sourcetype);
128 if ($action ==
"delete" && $usercancreate) {
129 if ($object->id > 0) {
130 $result = $object->demande_prelevement_delete($user,
GETPOST(
'did',
'int'));
132 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id.
'&type='.$type);
139 if ($action ==
'setconditions' && $usercancreate) {
141 $object->cond_reglement_code = 0;
142 $object->cond_reglement_id = 0;
149 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
157 $old_date_echeance = $object->date_echeance;
158 $new_date_echeance = $object->calculate_date_lim_reglement();
159 if ($new_date_echeance > $old_date_echeance) {
160 $object->date_echeance = $new_date_echeance;
162 if ($object->date_echeance < $object->date) {
163 $object->date_echeance = $object->date;
165 $result = $object->update($user);
177 } elseif ($action ==
'setmode' && $usercancreate) {
179 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
180 } elseif ($action ==
'setdatef' && $usercancreate) {
182 if ($newdate > (
dol_now(
'tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
183 if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
184 setEventMessages($langs->trans(
"WarningInvoiceDateInFuture"),
null,
'warnings');
186 setEventMessages($langs->trans(
"WarningInvoiceDateTooFarInFuture"),
null,
'warnings');
190 $object->date = $newdate;
191 $date_echence_calc = $object->calculate_date_lim_reglement();
192 if (!empty($object->date_echeance) && $object->date_echeance < $date_echence_calc) {
193 $object->date_echeance = $date_echence_calc;
195 if ($object->date_echeance && $object->date_echeance < $object->date) {
196 $object->date_echeance = $object->date;
199 $result = $object->update($user);
203 } elseif ($action ==
'setdate_lim_reglement' && $usercancreate) {
204 $object->date_echeance =
dol_mktime(12, 0, 0,
GETPOST(
'date_lim_reglementmonth',
'int'),
GETPOST(
'date_lim_reglementday',
'int'),
GETPOST(
'date_lim_reglementyear',
'int'));
205 if (!empty($object->date_echeance) && $object->date_echeance < $object->date) {
206 $object->date_echeance = $object->date;
207 setEventMessages($langs->trans(
"DatePaymentTermCantBeLowerThanObjectDate"),
null,
'warnings');
209 $result = $object->update($user);
225 if ($type ==
'bank-transfer') {
226 $title = $langs->trans(
'SupplierInvoice').
" - ".$langs->trans(
'CreditTransfer');
229 $title = $langs->trans(
'InvoiceCustomer').
" - ".$langs->trans(
'StandingOrders');
230 $helpurl =
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
236 if ($object->id > 0) {
237 $selleruserevenustamp = $mysoc->useRevenueStamp();
239 $totalpaid = $object->getSommePaiement();
240 $totalcreditnotes = $object->getSumCreditNotesUsed();
241 $totaldeposits = $object->getSumDepositsUsed();
248 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
253 $resteapayeraffiche = $resteapayer;
255 if ($type ==
'bank-transfer') {
256 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
257 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
258 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
260 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
261 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
264 $absolute_discount = $object->thirdparty->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
265 $absolute_creditnote = $object->thirdparty->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
266 $absolute_discount =
price2num($absolute_discount,
'MT');
267 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
269 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
270 $filterabsolutediscount =
"fk_facture_source IS NULL";
271 $filtercreditnote =
"fk_facture_source IS NOT NULL";
273 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
274 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
277 $absolute_discount = $object->thirdparty->getAvailableDiscounts(
'', $filterabsolutediscount);
278 $absolute_creditnote = $object->thirdparty->getAvailableDiscounts(
'', $filtercreditnote);
279 $absolute_discount =
price2num($absolute_discount,
'MT');
280 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
283 $author =
new User($db);
284 if ($object->fk_user_author) {
285 $author->fetch($object->fk_user_author);
288 if ($type ==
'bank-transfer') {
300 $sql =
"SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
301 $sql .=
" , pfd.date_traite as date_traite";
302 $sql .=
" , pfd.amount";
303 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_facture_demande as pfd";
304 if ($type ==
'bank-transfer') {
305 $sql .=
" WHERE fk_facture_fourn = ".((int) $object->id);
307 $sql .=
" WHERE fk_facture = ".((int) $object->id);
309 $sql .=
" AND pfd.traite = 0";
310 $sql .=
" AND pfd.ext_payment_id IS NULL";
311 $sql .=
" ORDER BY pfd.date_demande DESC";
313 $resql = $db->query($sql);
315 $num = $db->num_rows(
$resql);
322 print
dol_get_fiche_head($head,
'standingorders', $title, -1, ($type ==
'bank-transfer' ?
'supplier_invoice' :
'bill'));
325 if ($type ==
'bank-transfer') {
326 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
328 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
331 $morehtmlref =
'<div class="refidno">';
333 if ($type ==
'bank-transfer') {
334 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, 0,
'string',
'', 0, 1);
335 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, 0,
'string',
'',
null,
null,
'', 1);
337 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, 0,
'string',
'', 0, 1);
338 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, 0,
'string',
'',
null,
null,
'', 1);
341 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$object->thirdparty->getNomUrl(1);
342 if ($type ==
'bank-transfer') {
343 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
344 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/facture/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
347 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
348 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherBills").
'</a>)';
353 $langs->load(
"projects");
354 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
355 if ($usercancreate) {
356 if ($action !=
'classify') {
358 $morehtmlref .=
' : ';
360 if ($action ==
'classify') {
362 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
363 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
364 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
365 $morehtmlref .=
'<input type="hidden" name="type" value="'.$type.
'">';
366 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
367 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
368 $morehtmlref .=
'</form>';
370 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
373 if (!empty($object->fk_project)) {
375 $proj->fetch($object->fk_project);
376 $morehtmlref .=
' : '.$proj->getNomUrl(1);
378 $morehtmlref .=
' - '.$proj->title;
385 $morehtmlref .=
'</div>';
387 $object->totalpaid = $totalpaid;
389 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref, $moreparam, 0,
'',
'');
391 print
'<div class="fichecenter">';
392 print
'<div class="fichehalfleft">';
393 print
'<div class="underbanner clearboth"></div>';
395 print
'<table class="border centpercent tableforfield">';
398 print
'<tr><td class="titlefield fieldname_type">'.$langs->trans(
'Type').
'</td><td colspan="3">';
399 print
'<span class="badgeneutral">';
400 print $object->getLibType();
402 if ($object->module_source) {
403 print
' <span class="opacitymediumbycolor paddingleft">('.$langs->trans(
"POS").
' '.$object->module_source.
' - '.$langs->trans(
"Terminal").
' '.$object->pos_source.
')</span>';
405 if ($object->type == $object::TYPE_REPLACEMENT) {
406 if ($type ==
'bank-transfer') {
409 $facreplaced =
new Facture($db);
411 $facreplaced->fetch($object->fk_facture_source);
412 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"ReplaceInvoice", $facreplaced->getNomUrl(1)).
'</span>';
414 if ($object->type == $object::TYPE_CREDIT_NOTE && !empty($object->fk_facture_source)) {
415 if ($type ==
'bank-transfer') {
420 $facusing->fetch($object->fk_facture_source);
421 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"CorrectInvoice", $facusing->getNomUrl(1)).
'</span>';
424 $facidavoir = $object->getListIdAvoirFromInvoice();
425 if (count($facidavoir) > 0) {
426 $invoicecredits = array();
427 foreach ($facidavoir as $facid) {
428 if ($type ==
'bank-transfer') {
433 $facavoir->fetch($facid);
434 $invoicecredits[] = $facavoir->getNomUrl(1);
436 print
' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities(
"InvoiceHasAvoir");
437 print
' '. (count($invoicecredits) ?
' ' :
'') . implode(
',', $invoicecredits);
450 print
'<!-- Discounts -->'.
"\n";
451 print
'<tr><td>'.$langs->trans(
'DiscountStillRemaining').
'</td><td colspan="3">';
453 if ($type ==
'bank-transfer') {
456 $thirdparty = $object->thirdparty;
459 $thirdparty = $object->thirdparty;
462 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?facid='.$object->id);
463 $cannotApplyDiscount = 1;
464 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
469 if ($type ==
'bank-transfer') {
471 print
'<td>'.$form->editfieldkey(
"Label",
'label', $object->label, $object, 0).
'</td>';
472 print
'<td>'.$form->editfieldval(
"Label",
'label', $object->label, $object, 0).
'</td>';
478 print
'<table class="nobordernopadding centpercent"><tr><td>';
479 print $langs->trans(
'DateInvoice');
481 if ($object->type != $object::TYPE_CREDIT_NOTE && $action !=
'editinvoicedate' && !empty($object->brouillon) && $user->rights->facture->creer) {
482 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editinvoicedate&token='.
newToken().
'&id='.$object->id.
'&type='.urlencode($type).
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
484 print
'</tr></table>';
485 print
'</td><td colspan="3">';
487 if ($object->type != $object::TYPE_CREDIT_NOTE) {
488 if ($action ==
'editinvoicedate') {
489 print
$form->form_date($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->date,
'invoicedate', 0, 0, 1, $type);
501 print
'<table class="nobordernopadding centpercent"><tr><td>';
502 print $langs->trans(
'PaymentConditionsShort');
504 if ($object->type != $object::TYPE_CREDIT_NOTE && $action !=
'editconditions' && !empty($object->brouillon) && $user->rights->facture->creer) {
505 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&token='.
newToken().
'&id='.$object->id.
'&type='.urlencode($type).
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
507 print
'</tr></table>';
508 print
'</td><td colspan="3">';
509 if ($object->type != $object::TYPE_CREDIT_NOTE) {
510 if ($action ==
'editconditions') {
511 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 0, $type);
513 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
522 print
'<table class="nobordernopadding centpercent"><tr><td>';
523 print $langs->trans(
'DateMaxPayment');
525 if ($object->type != $object::TYPE_CREDIT_NOTE && $action !=
'editpaymentterm' && !empty($object->brouillon) && $user->rights->facture->creer) {
526 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editpaymentterm&token='.
newToken().
'&id='.$object->id.
'&type='.urlencode($type).
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
528 print
'</tr></table>';
529 print
'</td><td colspan="3">';
530 if ($object->type != $object::TYPE_CREDIT_NOTE) {
531 $duedate = $object->date_lim_reglement;
532 if ($type ==
'bank-transfer') {
533 $duedate = $object->date_echeance;
536 if ($action ==
'editpaymentterm') {
537 print
$form->form_date($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $duedate,
'paymentterm', 0, 0, 1, $type);
540 if ($object->hasDelay()) {
551 print
'<table class="nobordernopadding centpercent"><tr><td>';
552 print $langs->trans(
'PaymentMode');
554 if ($action !=
'editmode' && !empty($object->brouillon) && $user->rights->facture->creer) {
555 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&id='.$object->id.
'&type='.urlencode($type).
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
557 print
'</tr></table>';
558 print
'</td><td colspan="3">';
559 $filtertype =
'CRDT';
560 if ($type ==
'bank-transfer') {
561 $filtertype =
'DBIT';
563 if ($action ==
'editmode') {
564 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id', $filtertype, 1, 0, $type);
566 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
571 print
'<tr><td class="nowrap">';
572 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
573 print $langs->trans(
'BankAccount');
575 if (($action !=
'editbankaccount') && $user->rights->commande->creer && !empty($object->brouillon)) {
576 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&token='.
newToken().
'&id='.$object->id.
'&type='.urlencode($type).
'">'.
img_edit($langs->trans(
'SetBankAccount'), 1).
'</a></td>';
578 print
'</tr></table>';
579 print
'</td><td colspan="3">';
580 if ($action ==
'editbankaccount') {
581 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
583 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
589 $title =
'CustomerIBAN';
590 if ($type ==
'bank-transfer') {
591 $title =
'SupplierIBAN';
593 print
'<tr><td>'.$langs->trans($title).
'</td><td colspan="3">';
596 $bac->fetch(0, $object->thirdparty->id);
598 print $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
599 if (!empty($bac->iban)) {
600 if ($bac->verif() <= 0) {
601 print
img_warning(
'Error on default bank number for IBAN : '.$bac->error_message);
604 if ($numopen || ($type !=
'bank-transfer' && $object->mode_reglement_code ==
'PRE') || ($type ==
'bank-transfer' && $object->mode_reglement_code ==
'VIR')) {
605 print
img_warning($langs->trans(
"NoDefaultIBANFound"));
614 print
'<div class="fichehalfright">';
615 print
'<div class="underbanner clearboth"></div>';
617 print
'<table class="border centpercent tableforfield">';
619 if (
isModEnabled(
'multicurrency') && ($object->multicurrency_code != $conf->currency)) {
621 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
622 print
'<td class="nowrap">'.price($object->multicurrency_total_ht,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
626 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
627 print
'<td class="nowrap">'.price($object->multicurrency_total_tva,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
631 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
632 print
'<td class="nowrap">'.price($object->multicurrency_total_ttc,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
637 print
'<tr><td class="titlefield">'.$langs->trans(
'AmountHT').
'</td>';
638 print
'<td class="nowrap">'.price($object->total_ht, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
641 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td colspan="3" class="nowrap">'.
price($object->total_tva, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
645 if (($mysoc->localtax1_assuj ==
"1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
646 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
647 print
'<td class="nowrap">'.price($object->total_localtax1, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
649 if (($mysoc->localtax2_assuj ==
"1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) {
650 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
651 print
'<td class=nowrap">'.price($object->total_localtax2, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
655 if ($selleruserevenustamp) {
657 print
'<table class="nobordernopadding" width="100%"><tr><td>';
658 print $langs->trans(
'RevenueStamp');
660 if ($action !=
'editrevenuestamp' && !empty($object->brouillon) && $user->rights->facture->creer) {
661 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editrevenuestamp&token='.
newToken().
'&facid='.$object->id.
'">'.
img_edit($langs->trans(
'SetRevenuStamp'), 1).
'</a></td>';
663 print
'</tr></table>';
665 print
price($object->revenuestamp, 1,
'', 1, - 1, - 1, $conf->currency);
670 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td class="nowrap">'.
price($object->total_ttc, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
672 $resteapayer =
price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
675 print
'<tr><td>'.$langs->trans(
'RemainderToPay').
'</td><td class="nowrap">'.
price($resteapayer, 1,
'', 1, - 1, - 1, $conf->currency).
'</td></tr>';
682 print
'<div class="clearboth"></div>';
690 $sql =
"SELECT SUM(pfd.amount) as amount";
691 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_facture_demande as pfd";
692 if ($type ==
'bank-transfer') {
693 $sql .=
" WHERE fk_facture_fourn = ".((int) $object->id);
695 $sql .=
" WHERE fk_facture = ".((int) $object->id);
697 $sql .=
" AND pfd.traite = 0";
698 $sql .=
" AND pfd.ext_payment_id IS NULL";
700 $resql = $db->query($sql);
702 $obj = $db->fetch_object(
$resql);
704 $pending = $obj->amount;
715 print
"\n<div class=\"tabsAction\">\n";
717 $buttonlabel = $langs->trans(
"MakeWithdrawRequest");
718 $user_perms = $user->rights->prelevement->bons->creer;
719 if ($type ==
'bank-transfer') {
720 $buttonlabel = $langs->trans(
"MakeBankTransferOrder");
721 $user_perms = $user->rights->paymentbybanktransfer->create;
725 if ($object->statut > $object::STATUS_DRAFT && $object->paye == 0 && $num == 0) {
726 if ($resteapayer > 0) {
728 $remaintopaylesspendingdebit = $resteapayer - $pending;
730 print
'<form method="POST" action="">';
731 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
732 print
'<input type="hidden" name="id" value="'.$object->id.
'" />';
733 print
'<input type="hidden" name="type" value="'.$type.
'" />';
734 print
'<input type="hidden" name="action" value="new" />';
735 print
'<label for="withdraw_request_amount">'.$langs->trans(
'BankTransferAmount').
' </label>';
736 print
'<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="'.$remaintopaylesspendingdebit.
'" size="9" />';
737 print
'<input type="submit" class="butAction" value="'.$buttonlabel.
'" />';
740 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">'.$buttonlabel.
'</a>';
743 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"AmountMustBePositive")).
'">'.$buttonlabel.
'</a>';
747 if ($object->statut > $object::STATUS_DRAFT) {
748 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"AlreadyPaid")).
'">'.$buttonlabel.
'</a>';
750 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"Draft")).
'">'.$buttonlabel.
'</a>';
753 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"RequestAlreadyDone")).
'">'.$buttonlabel.
'</a>';
757 print
"</div><br>\n";
760 if ($type ==
'bank-transfer') {
761 print
'<div class="opacitymedium">'.$langs->trans(
"DoCreditTransferBeforePayments").
'</div><br>';
763 print
'<div class="opacitymedium">'.$langs->trans(
"DoStandingOrdersBeforePayments").
'</div><br>';
770 print
'<div class="div-table-responsive-no-min">';
771 print
'<table class="noborder centpercent">';
773 print
'<tr class="liste_titre">';
774 print
'<td class="left">'.$langs->trans(
"DateRequest").
'</td>';
775 print
'<td class="center">'.$langs->trans(
"User").
'</td>';
776 print
'<td class="center">'.$langs->trans(
"Amount").
'</td>';
777 if ($type ==
'bank-transfer') {
778 print
'<td class="center">'.$langs->trans(
"BankTransferReceipt").
'</td>';
780 print
'<td class="center">'.$langs->trans(
"WithdrawalReceipt").
'</td>';
782 print
'<td> </td>';
783 print
'<td class="center">'.$langs->trans(
"DateProcess").
'</td>';
784 print
'<td> </td>';
787 $sql =
"SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande,";
788 $sql .=
" pfd.date_traite as date_traite, pfd.amount,";
789 $sql .=
" u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status";
790 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_facture_demande as pfd";
791 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on pfd.fk_user_demande = u.rowid";
792 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
793 if ($type ==
'bank-transfer') {
794 $sql .=
" WHERE fk_facture_fourn = ".((int) $object->id);
796 $sql .=
" WHERE fk_facture = ".((int) $object->id);
798 $sql .=
" AND pfd.traite = 0";
799 $sql .=
" AND pfd.ext_payment_id IS NULL";
800 $sql .=
" ORDER BY pfd.date_demande DESC";
802 $resql = $db->query($sql);
808 $tmpuser =
new User($db);
810 $num = $db->num_rows($result);
812 $obj = $db->fetch_object(
$resql);
814 $tmpuser->id = $obj->user_id;
815 $tmpuser->login = $obj->login;
816 $tmpuser->ref = $obj->login;
817 $tmpuser->email = $obj->email;
818 $tmpuser->lastname = $obj->lastname;
819 $tmpuser->firstname = $obj->firstname;
820 $tmpuser->statut = $obj->user_status;
822 print
'<tr class="oddeven">';
824 print
'<td class="left">'.dol_print_date($db->jdate($obj->date_demande),
'dayhour').
"</td>\n";
826 print
'<td align="center">';
827 print $tmpuser->getNomUrl(1,
'', 0, 0, 0, 0,
'login');
830 print
'<td class="center">'.price($obj->amount).
'</td>';
831 print
'<td align="center">-</td>';
832 print
'<td> </td>';
834 print
'<td class="center">'.$langs->trans(
"OrderWaiting").
'</td>';
836 print
'<td class="right">';
837 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'&did='.$obj->rowid.
'&type='.$type.
'">';
853 $sql =
"SELECT pfd.rowid, pfd.traite, pfd.date_demande, pfd.date_traite, pfd.fk_prelevement_bons, pfd.amount,";
855 $sql .=
" u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status";
856 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_facture_demande as pfd";
857 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on pfd.fk_user_demande = u.rowid";
858 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
859 if ($type ==
'bank-transfer') {
860 $sql .=
" WHERE fk_facture_fourn = ".((int) $object->id);
862 $sql .=
" WHERE fk_facture = ".((int) $object->id);
864 $sql .=
" AND pfd.traite = 1";
865 $sql .=
" AND pfd.ext_payment_id IS NULL";
866 $sql .=
" ORDER BY pfd.date_demande DESC";
868 $result = $db->query($sql);
870 $num = $db->num_rows($result);
874 $tmpuser =
new User($db);
877 $obj = $db->fetch_object($result);
879 $tmpuser->id = $obj->user_id;
880 $tmpuser->login = $obj->login;
881 $tmpuser->ref = $obj->login;
882 $tmpuser->email = $obj->email;
883 $tmpuser->lastname = $obj->lastname;
884 $tmpuser->firstname = $obj->firstname;
885 $tmpuser->statut = $obj->user_status;
887 print
'<tr class="oddeven">';
889 print
'<td class="left">'.dol_print_date($db->jdate($obj->date_demande),
'day').
"</td>\n";
891 print
'<td align="center">';
892 print $tmpuser->getNomUrl(1,
'', 0, 0, 0, 0,
'login');
895 print
'<td class="center">'.price($obj->amount).
'</td>';
897 print
'<td class="center">';
898 if ($obj->fk_prelevement_bons > 0) {
900 $withdrawreceipt->id = $obj->fk_prelevement_bons;
901 $withdrawreceipt->ref = $obj->ref;
902 print $withdrawreceipt->getNomUrl(1);
906 print
'<td> </td>';
908 print
'<td class="center">'.dol_print_date($db->jdate($obj->date_traite),
'day').
"</td>\n";
910 print
'<td> </td>';
916 if (!$numopen && !$numclosed) {
917 print
'<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';