* Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2012 Cédric Salvador * Copyright (C) 2014 Raphaël Doursenaud * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> * Copyright (C) 2015 Juanjo Menent * Copyright (C) 2018-2019 Thibault FOUCART * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/stripe/payment.php * \ingroup stripe * \brief Payment page for customers invoices */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; // Load translation files required by the page $langs->loadLangs(array('companies', 'bills', 'banks', 'multicurrency', 'stripe')); $action = GETPOST('action', 'alpha'); $confirm = GETPOST('confirm'); $facid = GETPOST('facid', 'int'); $socname = GETPOST('socname'); $source = GETPOST('source_id'); $accountid = GETPOST('accountid'); $paymentnum = GETPOST('num_paiement'); $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page', 'int'); $amounts=array(); $amountsresttopay=array(); $addwarning=0; $multicurrency_amounts=array(); $multicurrency_amountsresttopay=array(); // Security check $socid=0; if ($user->societe_id > 0) { $socid = $user->societe_id; } $object=new Facture($db); // Load object if ($facid > 0) { $ret=$object->fetch($facid); } if (! empty($conf->stripe->enabled)) { access_forbidden(); } if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha')) { $service = 'StripeTest'; $servicestatus = '0'; dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning'); } else { $service = 'StripeLive'; $servicestatus = '1'; } $stripeacc = $stripe->getStripeAccount($service); /*if (empty($stripeaccount)) { print $langs->trans('ErrorStripeAccountNotDefined'); }*/ // Initialize technical object to manage hooks of paiements. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('paiementcard','globalcard')); /* * Actions */ $parameters=array('socid'=>$socid); $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if (empty($reshook)) { if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes')) { $error = 0; $datepaye = dol_now(); $paiement_id = 0; $totalpayment = 0; $multicurrency_totalpayment = 0; $atleastonepaymentnotnull = 0; // Generate payment array and check if there is payment higher than invoice and payment date before invoice date $tmpinvoice=new Facture($db); foreach ($_POST as $key => $value) { if (substr($key, 0, 7) == 'amount_') { $cursorfacid = substr($key, 7); $amounts[$cursorfacid] = price2num(trim(GETPOST($key))); $totalpayment = $totalpayment + $amounts[$cursorfacid]; if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++; $result=$tmpinvoice->fetch($cursorfacid); if ($result <= 0) dol_print_error($db); $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement()); if ($amounts[$cursorfacid]) { // Check amount if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) { $addwarning=1; $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay"); } // Check date if ($datepaye && ($datepaye < $tmpinvoice->date)) { $langs->load("errors"); //$error++; setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); } } $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]); } elseif (substr($key, 0, 21) == 'multicurrency_amount_') { $cursorfacid = substr($key, 21); $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key))); $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid]; if (! empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++; $result=$tmpinvoice->fetch($cursorfacid); if ($result <= 0) dol_print_error($db); $multicurrency_amountsresttopay[$cursorfacid]=price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1)); if ($multicurrency_amounts[$cursorfacid]) { // Check amount if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid]))) { $addwarning=1; $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay"); } // Check date if ($datepaye && ($datepaye < $tmpinvoice->date)) { $langs->load("errors"); //$error++; setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); } } $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => GETPOST($key, 'int')); } } // Check parameters // if (! GETPOST('paiementcode')) // { // setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), null, 'errors'); // $error++; // } if (! empty($conf->banque->enabled)) { // If bank module is on, account is required to enter a payment if (GETPOST('accountid') <= 0) { setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors'); $error++; } } if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) { setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->trans('PaymentAmount')), null, 'errors'); $error++; } // if (empty($datepaye)) // { // setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), null, 'errors'); // $error++; // } // Check if payments in both currency if ($totalpayment > 0 && $multicurrency_totalpayment > 0) { setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors'); $error++; } } /* * Action add_paiement */ if ($action == 'add_paiement') { if ($error) { $action = 'create'; if (!$source) { setEventMessages($langs->transnoentities('NoSource'), null, 'errors'); } $error++; } // Le reste propre a cette action s'affiche en bas de page. } /* * Action confirm_paiement */ if ($action == 'confirm_paiement' && $confirm == 'yes') { $error=0; $datepaye = dol_now(); $db->begin(); // Clean parameters amount if payment is for a credit note if (GETPOST('type') == 2) { foreach ($amounts as $key => $value) // How payment is dispatch { $newvalue = price2num($value, 'MT'); $amounts[$key] = -$newvalue; } foreach ($multicurrency_amounts as $key => $value) // How payment is dispatch { $newvalue = price2num($value, 'MT'); $multicurrency_amounts[$key] = -$newvalue; } } if (! empty($conf->banque->enabled)) { // Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement if (GETPOST('accountid') <= 0) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors'); $error++; } } $facture = new Facture($db); $facture->fetch($facid); $facture->fetch_thirdparty(); $error = 0; if (is_object($stripe) && $stripeacc) { $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus); if ($customerstripe->id) { $listofsources=$customerstripe->sources->data; } } $stripeamount=0; foreach ($amounts as $key => $value) // How payment is dispatch { $stripeamount+=price2num($value, 'MT'); } if (preg_match('/acct_/i', $source)) { $paiementcode ="VIR"; } elseif (preg_match('/card_/i', $source)) { $paiementcode ="CB"; } elseif (preg_match('/src_/i', $source)) { $customer2 = $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus); $src = $customer2->sources->retrieve("$source"); if ($src->type=='card') { $paiementcode ="CB"; } } $societe = new Societe($db); $societe->fetch($facture->socid); dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe'); $stripecu = $stripe->getStripeCustomerAccount($societe->id, $servicestatus); // Get thirdparty cu_... $charge=$stripe->createPaymentStripe($stripeamount, $facture->multicurrency_code, "invoice", $facid, $source, $stripecu, $stripeacc, $servicestatus); if (!$error) { // Creation of payment line $paiement = new Paiement($db); $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Array with all payments dispatching $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching $paiement->paiementid = dol_getIdFromCode($db, $paiementcode, 'c_paiement'); $paiement->num_paiement = $charge->message; $paiement->note = GETPOST('comment'); $paiement->ext_payment_id = $charge->id; $paiement->ext_payment_site = $service; } if (! $error) { $paiement_id = $paiement->create($user, 0); if ($paiement_id < 0) { setEventMessages($paiement->error, $paiement->errors, 'errors'); $error++; } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($facture->lines)) { $outputlangs = $langs; $newlang = ''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $facture->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } $model=$facture->modelpdf; $ret = $facture->fetch($facid); // Reload to get new records $facture->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } if (! $error) { $label='(CustomerInvoicePayment)'; if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)'; $result=$paiement->addPaymentToBank($user, 'payment', $label, GETPOST('accountid'), '', ''); if ($result < 0) { setEventMessages($paiement->error, $paiement->errors, 'errors'); $error++; } elseif (GETPOST('closepaidinvoices')=='on') { $facture->set_paid($user); } } if (! $error) { $db->commit(); // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card $invoiceid=0; foreach ($paiement->amounts as $key => $amount) { $facid = $key; if (is_numeric($amount) && $amount <> 0) { if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment else $invoiceid=$facid; } } if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid; else $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id; header('Location: '.$loc); exit; } else { $loc = DOL_URL_ROOT.'/stripe/payment.php?facid='.$facid.'&action=create&error='.$charge->message; $db->rollback(); header('Location: '.$loc); exit; } } } /* * View */ $form = new Form($db); llxHeader(); if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox', 'alpha')) { $service = 'StripeLive'; $servicestatus = 0; } else { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning'); } if (GETPOST('error')){ setEventMessages(GETPOST('error'), null, 'errors'); } if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement') { $facture = new Facture($db); $result=$facture->fetch($facid); if ($result >= 0) { $facture->fetch_thirdparty(); $title=''; if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer"); if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer"); print load_fiche_titre($title); // Initialize data for confirmation (this is used because data can be change during confirmation) if ($action == 'add_paiement') { $i=0; $formquestion[$i++]=array('type' => 'hidden','name' => 'facid', 'value' => $facture->id); $formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid); $formquestion[$i++]=array('type' => 'hidden','name' => 'type', 'value' => $facture->type); } // Add realtime total information if ($conf->use_javascript_ajax) { print "\n".''."\n"; } print '
'; print ''; print ''; print ''; print ''; print ''; print ''; dol_fiche_head(); print ''; // Invoice /*if ($facture->id > 0) { print '\n"; }*/ // Third party print '\n"; // Bank account if (! empty($conf->banque->enabled)) { //$form->select_comptes($accountid,'accountid',0,'',2); print ''; } else { print ''; } // Cheque number //print ''; //print ''; // Check transmitter //print ''; //print ''; // Bank name //print ''; //print ''; // Comments print ''; print ''; print '
'.$langs->trans('Invoice').''.$facture->getNomUrl(4)."
'.$langs->trans('Company').''.$facture->thirdparty->getNomUrl(4)."
'.$langs->trans('Numero'); //print ' ('.$langs->trans("ChequeOrTransferNumber").')'; //print '
'.$langs->trans('CheckTransmitter'); //print ' ('.$langs->trans("ChequeMaker").')'; //print '
'.$langs->trans('Bank'); //print ' ('.$langs->trans("ChequeBank").')'; //print '
'.$langs->trans('Comments').''; print '
'; dol_fiche_end(); $customerstripe=$stripe->customerStripe($facture->thirdparty, $stripeacc, $servicestatus); print '
'; print_barre_liste($langs->trans('StripeSourceList').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', ''); print ''."\n"; // Titles with sort buttons print ''; print ''; print ''; print ''; print ''; print "\n"; foreach ($customerstripe->sources->data as $src) { print ''; print ''; print ''; print ''; // Default print ''; print ''; } // TODO more dolibarize with new stripe function and stripeconnect //if ($stripe->getStripeCustomerAccount($facture->socid)) { // $account=\Stripe\Account::retrieve("".$stripe->getStripeCustomerAccount($facture->socid).""); //} if (($account->type=='custom' or $account->type=='express') && $entity==1) { print ''; print ''; print ''; // Default print ''; print ''; } if (empty($input)&&!$stripe->getStripeCustomerAccount($facture->socid)) { print ''; } print "
'.$langs->trans('Type').''.$langs->trans('Informations').'
id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { print'class="opacitymedium"'; } print '>id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { print ' disabled'; } elseif (($customerstripe->default_source==$src->id && $action != 'add_paiement') or ($source==$src->id && $action == 'add_paiement')) { print ' checked'; } print '>id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { print'class="opacitymedium"'; } print' >'; if ($src->object=='card') { print img_credit_card($src->brand); } elseif ($src->object=='source' && $src->type=='card') { print img_credit_card($src->card->brand); } elseif ($src->object=='source' && $src->type=='sepa_debit') { print ''; } print 'id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { print'class="opacitymedium"'; } print' >'; if ($src->object=='card') { print '....'.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.''; print ''; if ($src->country) { $img = picto_from_langcode($src->country); print $img?$img.' ':''; print getCountry($src->country, 1); } else { print img_warning().' '.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).''; } } elseif ($src->object=='source' && $src->type=='card') { print $src->owner->name.'
....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.''; print '
'; if ($src->card->country) { $img = picto_from_langcode($src->card->country); print $img?$img.' ':''; print getCountry($src->card->country, 1); } else { print img_warning().' '.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).''; } } elseif ($src->object=='source' && $src->type=='sepa_debit') { print 'info sepa'; print ''; if ($src->sepa_debit->country) { $img = picto_from_langcode($src->sepa_debit->country); print $img?$img.' ':''; print getCountry($src->sepa_debit->country, 1); } else { print img_warning().' '.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).''; } } print 'id!=$source) or ($src->object=='source' && $src->card->three_d_secure=='required')) { print'class="opacitymedium"'; } print'>'; if (($customerstripe->default_source==$src->id)) { print ""; } print '
getStripeCustomerAccount($facture->socid)!=$source) { print'class="opacitymedium"'; } print'>global->STRIPE_EXTERNAL_ACCOUNT && $action == 'add_paiement')) { print ' checked'; } elseif ($action == 'add_paiement' && $conf->global->STRIPE_EXTERNAL_ACCOUNT!=$source) { print ' disabled'; } print '>getStripeCustomerAccount($facture->socid)!=$source) { print'class="opacitymedium"'; } print '>getStripeCustomerAccount($facture->socid)!=$source) { print'class="opacitymedium"'; } print'>'.$langs->trans('sold'); print'id!=$source) { print'class="opacitymedium"'; } print'>'; print 'id!=$source) { print'class="opacitymedium"'; } print'>'; //if (($customer->default_source!=$src->id)) { // print img_picto($langs->trans("Disabled"),'off'); //} else { // print img_picto($langs->trans("Default"),'on'); //} print '
'.$langs->trans("None").'
"; /* * List of unpaid invoices */ $sql = 'SELECT f.rowid as facid, f.ref, f.total_ttc, f.multicurrency_code, f.multicurrency_total_ttc, f.type, '; $sql.= ' f.datef as df, f.fk_soc as socid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)'; } $sql.= ' WHERE f.entity IN ('.getEntity('invoice').")"; $sql.= ' AND (f.fk_soc = '.$facture->socid; if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) { $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')'; } $sql.= ') AND f.paye = 0'; $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled if ($facture->type != 2) { $sql .= ' AND type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation } else { $sql .= ' AND type = 2'; // If paying back a credit note, we show all credit notes } // Sort invoices by date and serial number: the older one comes first $sql.=' ORDER BY f.datef ASC, f.ref ASC'; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num > 0) { $sign=1; if ($facture->type == 2) $sign=-1; $arraytitle=$langs->trans('Invoice'); if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes"); $alreadypayedlabel=$langs->trans('Received'); $multicurrencyalreadypayedlabel=$langs->trans('MulticurrencyReceived'); if ($facture->type == 2) { $alreadypayedlabel=$langs->trans("PaidBack"); $multicurrencyalreadypayedlabel=$langs->trans("MulticurrencyPaidBack"); } $remaindertopay=$langs->trans('RemainderToTake'); $multicurrencyremaindertopay=$langs->trans('MulticurrencyRemainderToTake'); if ($facture->type == 2) { $remaindertopay=$langs->trans("RemainderToPayBack"); $multicurrencyremaindertopay=$langs->trans("MulticurrencyRemainderToPayBack"); } $i = 0; print '
'; print_barre_liste($langs->trans('StripeInvoiceList').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', ''); print ''; print ''; print ''; print ''; if (!empty($conf->multicurrency->enabled)) { print ''; print ''; print ''; print ''; } print ''; print ''; print ''; print ''; if (!empty($conf->multicurrency->enabled)) { print ''; } $tmpinvoice =new Facture($db); $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $tmpinvoice, $action); // Note that $action and $object may have been modified by hook print ''; print "\n"; $total=0; $totalrecu=0; $totalrecucreditnote=0; $totalrecudeposits=0; while ($i < $num) { $objp = $db->fetch_object($resql); $soc = new Societe($db); $soc->fetch($objp->socid); $invoice=new Facture($db); $invoice->fetch($objp->facid); $paiement = $invoice->getSommePaiement(); $creditnotes=$invoice->getSumCreditNotesUsed(); $deposits=$invoice->getSumDepositsUsed(); $alreadypayed=price2num($paiement + $creditnotes + $deposits, 'MT'); $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT'); // Multicurrency Price if (!empty($conf->multicurrency->enabled)) { $multicurrency_payment = $invoice->getSommePaiement(1); $multicurrency_creditnotes=$invoice->getSumCreditNotesUsed(1); $multicurrency_deposits=$invoice->getSumDepositsUsed(1); $multicurrency_alreadypayed=price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits, 'MT'); $multicurrency_remaintopay=price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits, 'MT'); } print ''; print '\n"; // Date print '\n"; // Currency if (!empty($conf->multicurrency->enabled)) print '\n"; // Multicurrency Price if (!empty($conf->multicurrency->enabled)) { print ''; // Multicurrency Price print ''; // Multicurrency Price print ''; } // Price print ''; // Received or paid back print ''; // Remain to take or to pay back print ''; //$test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits)); // Amount print '"; // Multicurrency Price if (! empty($conf->multicurrency->enabled)) { print '"; } $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook // Warning print ''; print "\n"; $total+=$objp->total; $total_ttc+=$objp->total_ttc; $totalrecu+=$paiement; $totalrecucreditnote+=$creditnotes; $totalrecudeposits+=$deposits; $i++; } if ($i > 1) { $amount=round(price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT'))*100); // Print total print ''; print ''; if (!empty($conf->multicurrency->enabled)) { print ''; print ''; print ''; } print ''; print ''; print ''; print ''; if (!empty($conf->multicurrency->enabled)) { print ''; } print ''; print "\n"; } print "
'.$arraytitle.''.$langs->trans('Date').''.$langs->trans('Currency').''.$langs->trans('MulticurrencyAmountTTC').''.$multicurrencyalreadypayedlabel.''.$multicurrencyremaindertopay.''.$langs->trans('AmountTTC').''.$alreadypayedlabel.''.$remaindertopay.''.$langs->trans('PaymentAmount').''.$langs->trans('MulticurrencyPaymentAmount').' 
'; print $invoice->getNomUrl(1, ''); if($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' '; print "'.dol_print_date($db->jdate($objp->df), 'day')."'.$objp->multicurrency_code."'; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $objp->multicurrency_total_ttc); print ''; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { print price($sign * $multicurrency_payment); if ($multicurrency_creditnotes) print '+'.price($multicurrency_creditnotes); if ($multicurrency_deposits) print '+'.price($multicurrency_deposits); } print ''; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $multicurrency_remaintopay); print ''.price($sign * $objp->total_ttc).''.price($sign * $paiement); if ($creditnotes) print '+'.price($creditnotes); if ($deposits) print '+'.price($deposits); print ''.price($sign * $remaintopay).''; // Add remind amount $namef = 'amount_'.$objp->facid; $nameRemain = 'remain_'.$objp->facid; if ($action != 'add_paiement') { if (!empty($conf->use_javascript_ajax)) print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'"); print ''; print ''; } else { print ''; print ''; } print "'; // Add remind multicurrency amount $namef = 'multicurrency_amount_'.$objp->facid; $nameRemain = 'multicurrency_remain_'.$objp->facid; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { if ($action != 'add_paiement') { if (!empty($conf->use_javascript_ajax)) print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'"); print ''; print ''; } else { print ''; print ''; } } print "'; //print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."
"; if ($amounts[$invoice->id] && (abs($amounts[$invoice->id]) > abs($amountsresttopay[$invoice->id])) || $multicurrency_amounts[$invoice->id] && (abs($multicurrency_amounts[$invoice->id]) > abs($multicurrency_amountsresttopay[$invoice->id]))) { print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay")); } print '
'.$langs->trans('TotalTTC').''.price($sign * $total_ttc).''.price($sign * $totalrecu); if ($totalrecucreditnote) print '+'.price($totalrecucreditnote); if ($totalrecudeposits) print '+'.price($totalrecudeposits); print ''.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).'
"; //print "\n"; } $db->free($resql); } else { dol_print_error($db); } // Bouton Enregistrer if ($action != 'add_paiement') { $checkboxlabel=$langs->trans("ClosePaidInvoicesAutomatically"); if ($facture->type == 2) $checkboxlabel=$langs->trans("ClosePaidCreditNotesAutomatically"); $buttontitle=$langs->trans('ToMakePayment'); if ($facture->type == 2) $buttontitle=$langs->trans('ToMakePaymentBack'); print '
'; print ' '.$checkboxlabel; /*if (! empty($conf->prelevement->enabled)) { $langs->load("withdrawals"); if (! empty($conf->global->WITHDRAW_DISABLE_AUTOCREATE_ONPAYMENTS)) print '
'.$langs->trans("IfInvoiceNeedOnWithdrawPaymentWontBeClosed"); }*/ print '


'; print '
'; } // Form to confirm payment if ($action == 'add_paiement') { $preselectedchoice=$addwarning?'no':'yes'; print '
'; if (!empty($totalpayment)) { $text = $langs->trans('ConfirmCustomerPayment', $totalpayment, $langs->trans("Currency".$conf->currency)); } if (!empty($multicurrency_totalpayment)) { $text.='
'.$langs->trans('ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->trans("paymentInInvoiceCurrency")); } if (GETPOST('closepaidinvoices')) { $text.='
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); print ''; } print $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type, $langs->trans('ReceivedCustomersPayments'), $text, 'confirm_paiement', $formquestion, $preselectedchoice); } print "
\n"; } } /** * Show list of payments */ if (! GETPOST('action')) { if ($page == -1) $page = 0 ; $limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; $offset = $limit * $page ; if (! $sortorder) $sortorder='DESC'; if (! $sortfield) $sortfield='p.datep'; $sql = 'SELECT p.datep as dp, p.amount, f.amount as fa_amount, f.ref'; $sql.=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement'; $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c'; $sql.= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id'; $sql.= ' AND f.entity IN ('.getEntity('invoice').")"; if ($socid) { $sql.= ' AND f.fk_soc = '.$socid; } $sql.= ' ORDER BY '.$sortfield.' '.$sortorder; $sql.= $db->plimit($limit+1, $offset); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; print_barre_liste($langs->trans('Payments'), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num); print ''; print ''; print_liste_field_titre('Invoice', $_SERVER["PHP_SELF"], 'ref', '', '', '', $sortfield, $sortorder); print_liste_field_titre('Date', $_SERVER["PHP_SELF"], 'dp', '', '', '', $sortfield, $sortorder); print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'libelle', '', '', '', $sortfield, $sortorder); print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], 'fa_amount', '', '', '', $sortfield, $sortorder, 'right '); $tmpobject = new Paiement($db); $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $tmpobject, $action); // Note that $action and $object may have been modified by hook print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch '); print "\n"; while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); print ''; print '\n"; print '\n"; print '\n"; print ''; $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook print ''; print ''; $i++; } print '
'.$objp->ref."'.dol_print_date($db->jdate($objp->dp))."'.$objp->paiement_type.' '.$objp->num_paiement."'.price($objp->amount).' 
'; } } // End of page llxFooter(); $db->close();