diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 7ed19ae9a1b..07f5dd234e9 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -346,45 +346,43 @@ $form = new Form($db); llxHeader('', $langs->trans("Payment")); - -if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement') { $facture = new Facture($db); $result = $facture->fetch($facid); - if ($result >= 0) { - $facture->fetch_thirdparty(); +if ($result >= 0) { + $facture->fetch_thirdparty(); - $title = ''; - if ($facture->type != Facture::TYPE_CREDIT_NOTE) { - $title .= $langs->trans("EnterPaymentReceivedFromCustomer"); + $title = ''; + if ($facture->type != Facture::TYPE_CREDIT_NOTE) { + $title .= $langs->trans("EnterPaymentReceivedFromCustomer"); + } + if ($facture->type == Facture::TYPE_CREDIT_NOTE) { + $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); + } + + // Invoice with Paypal transaction + // @TODO add hook here + if (isModEnabled('paypalplus') && getDolGlobalString('PAYPAL_ENABLE_TRANSACTION_MANAGEMENT') && !empty($facture->ref_ext)) { + if (getDolGlobalString('PAYPAL_BANK_ACCOUNT')) { + $accountid = getDolGlobalString('PAYPAL_BANK_ACCOUNT'); } - if ($facture->type == Facture::TYPE_CREDIT_NOTE) { - $title .= $langs->trans("EnterPaymentDueToCustomer"); - } - print load_fiche_titre($title); + $paymentnum = $facture->ref_ext; + } - // 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); - } - - // Invoice with Paypal transaction - // @TODO add hook here - if (isModEnabled('paypalplus') && getDolGlobalString('PAYPAL_ENABLE_TRANSACTION_MANAGEMENT') && !empty($facture->ref_ext)) { - if (getDolGlobalString('PAYPAL_BANK_ACCOUNT')) { - $accountid = getDolGlobalString('PAYPAL_BANK_ACCOUNT'); - } - $paymentnum = $facture->ref_ext; - } - - // Add realtime total information - if (!empty($conf->use_javascript_ajax)) { - print "\n".''."\n"; + print ' '."\n"; + } + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print dol_get_fiche_head(); + + print ''; + + // Third party + print '\n"; + + // Date payment + print ''; + + // Payment mode + print '\n"; + print ''; + + // Bank account + print ''; + if (isModEnabled("bank")) { + if ($facture->type != 2) { + print ''; + } + if ($facture->type == 2) { + print ''; } - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + } else { + print ''; + } + print "\n"; - print dol_get_fiche_head(); + // Bank check number + print ''; + print ''; - print '
'.$langs->trans('Company').''.$facture->thirdparty->getNomUrl(4)."
'.$langs->trans('Date').''; + $datepayment = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear')); + $datepayment = ($datepayment == '' ? (!getDolGlobalString('MAIN_AUTOFILL_DATE') ? -1 : '') : $datepayment); + print $form->selectDate($datepayment, '', 0, 0, 0, "add_paiement", 1, 1, 0, '', '', $facture->date); + print '
'.$langs->trans('PaymentMode').''; + $form->select_types_paiements((GETPOST('paiementcode') ? GETPOST('paiementcode') : $facture->mode_reglement_code), 'paiementcode', '', 2); + print "
'.$langs->trans('AccountToCredit').''.$langs->trans('AccountToDebit').''; + print img_picto('', 'bank_account', 'class="pictofixedwidth"'); + print $form->select_comptes($accountid, 'accountid', 0, '', 2, '', (isModEnabled('multicurrency') ? 1 : 0), 'widthcentpercentminusx maxwidth500', 1); + print ' 
'.$langs->trans('Numero'); + print ' ('.$langs->trans("ChequeOrTransferNumber").')'; + print '
'; + // Check transmitter + print ''; + print ''; - // Third party - print '\n"; + // Bank name + print ''; + print ''; - // Date payment - print ''; + print ''; + + // Go Source Invoice (useful when there are many invoices) + if ($action != 'add_paiement' && getDolGlobalString('FACTURE_PAYMENTS_SHOW_LINK_TO_INPUT_ORIGIN_IS_MORE_THAN')) { + print ''; + print ''; + } - // Payment mode - print '\n"; - print ''; + print '
'.$langs->trans('CheckTransmitter'); + print ' ('.$langs->trans("ChequeMaker").')'; + print '
'.$langs->trans('Company').''.$facture->thirdparty->getNomUrl(4)."
'.$langs->trans('Bank'); + print ' ('.$langs->trans("ChequeBank").')'; + print '
'.$langs->trans('Date').''; - $datepayment = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear')); - $datepayment = ($datepayment == '' ? (!getDolGlobalString('MAIN_AUTOFILL_DATE') ? -1 : '') : $datepayment); - print $form->selectDate($datepayment, '', 0, 0, 0, "add_paiement", 1, 1, 0, '', '', $facture->date); + // Comments + print '
'.$langs->trans('Comments').''; + print ''; + print '
'; + print ''.$langs->trans("GoSourceInvoice").''; print '
'.$langs->trans('PaymentMode').''; - $form->select_types_paiements((GETPOST('paiementcode') ? GETPOST('paiementcode') : $facture->mode_reglement_code), 'paiementcode', '', 2); - print "
'; - // Bank account - print ''; - if (isModEnabled("bank")) { - if ($facture->type != 2) { - print ''.$langs->trans('AccountToCredit').''; - } + print dol_get_fiche_end(); + + + /* + * List of unpaid invoices + */ + + $sql = 'SELECT f.rowid as facid, f.ref, f.total_ht, f.total_tva, f.total_ttc, f.multicurrency_code, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc, f.type,'; + $sql .= ' f.datef as df, f.fk_soc as socid, f.date_lim_reglement as dlr'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f'; + $sql .= ' WHERE f.entity IN ('.getEntity('facture').')'; + $sql .= ' AND (f.fk_soc = '.((int) $facture->socid); + // Can pay invoices of all child of parent company + if (getDolGlobalString('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 = '.((int) $facture->thirdparty->parent).')'; + } + // Can pay invoices of all child of myself + if (getDolGlobalString('FACTURE_PAYMENTS_ON_SUBSIDIARY_COMPANIES')) { + $sql .= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.((int) $facture->thirdparty->id).')'; + } + $sql .= ') AND f.paye = 0'; + $sql .= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled + if ($facture->type != Facture::TYPE_CREDIT_NOTE) { + $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) { + $arraytitle = $langs->trans('Invoice'); if ($facture->type == 2) { - print ''.$langs->trans('AccountToDebit').''; + $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"); } - print ''; - print img_picto('', 'bank_account', 'class="pictofixedwidth"'); - print $form->select_comptes($accountid, 'accountid', 0, '', 2, '', (isModEnabled('multicurrency') ? 1 : 0), 'widthcentpercentminusx maxwidth500', 1); - print ''; - } else { - print ' '; - } - print "\n"; + $i = 0; + //print ''; + print '
'; - // Bank check number - print ''.$langs->trans('Numero'); - print ' ('.$langs->trans("ChequeOrTransferNumber").')'; - print ''; - print ''; + print '
'; // You can use div-table-responsive-no-min if you don't need reserved height for your table + print ''; - // Check transmitter - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + if (isModEnabled('multicurrency')) { + print ''; + print ''; + print ''; + print ''; + print ''; + } + print ''; + print ''; + print ''; + print ''; - // Bank name - print ''; - print ''; + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $facture, $action); // Note that $action and $object may have been modified by hook - // Comments - print ''; - print ''; + print ''; + print "\n"; - // Go Source Invoice (useful when there are many invoices) - if ($action != 'add_paiement' && getDolGlobalString('FACTURE_PAYMENTS_SHOW_LINK_TO_INPUT_ORIGIN_IS_MORE_THAN')) { - print ''; - print ''; - } + $total_ttc = 0; + $totalrecu = 0; + $totalrecucreditnote = 0; + $totalrecudeposits = 0; + $sign = 1; - print '
'.$langs->trans('CheckTransmitter'); - print ' ('.$langs->trans("ChequeMaker").')'; - print '
'.$arraytitle.''.$langs->trans('Date').''.$langs->trans('DateMaxPayment').''.$langs->trans('Currency').''.$langs->trans('MulticurrencyAmountTTC').''.$multicurrencyalreadypayedlabel.''.$multicurrencyremaindertopay.''.$langs->trans('MulticurrencyPaymentAmount').''.$langs->trans('AmountTTC').''.$alreadypayedlabel.''.$remaindertopay.''.$langs->trans('PaymentAmount').'
'.$langs->trans('Bank'); - print ' ('.$langs->trans("ChequeBank").')'; - print '
'.$langs->trans('Comments').''; - print ''; - print '
 
'; - print ''.$langs->trans("GoSourceInvoice").''; - print '
'; + while ($i < $num) { + $objp = $db->fetch_object($resql); - print dol_get_fiche_end(); - - - /* - * List of unpaid invoices - */ - - $sql = 'SELECT f.rowid as facid, f.ref, f.total_ht, f.total_tva, f.total_ttc, f.multicurrency_code, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc, f.type,'; - $sql .= ' f.datef as df, f.fk_soc as socid, f.date_lim_reglement as dlr'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f'; - $sql .= ' WHERE f.entity IN ('.getEntity('facture').')'; - $sql .= ' AND (f.fk_soc = '.((int) $facture->socid); - // Can pay invoices of all child of parent company - if (getDolGlobalString('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 = '.((int) $facture->thirdparty->parent).')'; - } - // Can pay invoices of all child of myself - if (getDolGlobalString('FACTURE_PAYMENTS_ON_SUBSIDIARY_COMPANIES')) { - $sql .= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.((int) $facture->thirdparty->id).')'; - } - $sql .= ') AND f.paye = 0'; - $sql .= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled - if ($facture->type != Facture::TYPE_CREDIT_NOTE) { - $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) { - $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 '
'; - - print '
'; // You can use div-table-responsive-no-min if you don't need reserved height for your table - print ''; - - print ''; - print ''; - print ''; - print ''; - if (isModEnabled('multicurrency')) { - print ''; - print ''; - print ''; - print ''; - print ''; - } - print ''; - print ''; - print ''; - print ''; - - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $facture, $action); // Note that $action and $object may have been modified by hook - - print ''; - print "\n"; - - $total_ttc = 0; - $totalrecu = 0; - $totalrecucreditnote = 0; - $totalrecudeposits = 0; $sign = 1; + if ($facture->type == Facture::TYPE_CREDIT_NOTE) { + $sign = -1; + } - while ($i < $num) { - $objp = $db->fetch_object($resql); + $soc = new Societe($db); + $soc->fetch($objp->socid); - $sign = 1; - if ($facture->type == Facture::TYPE_CREDIT_NOTE) { - $sign = -1; + $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 + $tooltiponmulticurrencyfullamount = ''; + $multicurrency_remaintopay = ''; + $multicurrency_payment = 0; + $multicurrency_creditnotes = 0; + $multicurrency_deposits = 0; + if (isModEnabled('multicurrency')) { + $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'); + // Multicurrency full amount tooltip + $tooltiponmulticurrencyfullamount = $langs->trans('AmountHT') . ": " . price($objp->multicurrency_total_ht, 0, $langs, 0, -1, -1, $objp->multicurrency_code) . "
"; + $tooltiponmulticurrencyfullamount .= $langs->trans('AmountVAT') . ": " . price($objp->multicurrency_total_tva, 0, $langs, 0, -1, -1, $objp->multicurrency_code) . "
"; + $tooltiponmulticurrencyfullamount .= $langs->trans('AmountTTC') . ": " . price($objp->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $objp->multicurrency_code) . "
"; + } + + // Full amount tooltip + $tooltiponfullamount = $langs->trans('AmountHT') . ": " . price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency) . "
"; + $tooltiponfullamount .= $langs->trans('AmountVAT') . ": " . price($objp->total_tva, 0, $langs, 0, -1, -1, $conf->currency) . "
"; + $tooltiponfullamount .= $langs->trans('AmountTTC') . ": " . price($objp->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) . "
"; + + print ''; + + print '\n"; + + // Date + print '\n"; + + // Due date + if ($objp->dlr > 0) { + print ''; + } else { + print ''; + } - $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'); + // Currency + if (isModEnabled('multicurrency')) { + print '\n"; + } - // Multicurrency Price - $tooltiponmulticurrencyfullamount = ''; - $multicurrency_remaintopay = ''; - $multicurrency_payment = 0; - $multicurrency_creditnotes = 0; - $multicurrency_deposits = 0; - if (isModEnabled('multicurrency')) { - $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'); - // Multicurrency full amount tooltip - $tooltiponmulticurrencyfullamount = $langs->trans('AmountHT') . ": " . price($objp->multicurrency_total_ht, 0, $langs, 0, -1, -1, $objp->multicurrency_code) . "
"; - $tooltiponmulticurrencyfullamount .= $langs->trans('AmountVAT') . ": " . price($objp->multicurrency_total_tva, 0, $langs, 0, -1, -1, $objp->multicurrency_code) . "
"; - $tooltiponmulticurrencyfullamount .= $langs->trans('AmountTTC') . ": " . price($objp->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $objp->multicurrency_code) . "
"; - } - - // Full amount tooltip - $tooltiponfullamount = $langs->trans('AmountHT') . ": " . price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency) . "
"; - $tooltiponfullamount .= $langs->trans('AmountVAT') . ": " . price($objp->total_tva, 0, $langs, 0, -1, -1, $conf->currency) . "
"; - $tooltiponfullamount .= $langs->trans('AmountTTC') . ": " . price($objp->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) . "
"; - - print ''; - - print '\n"; - - // Date - print '\n"; - - // Due date - if ($objp->dlr > 0) { - print ''; - } else { - print ''; - } - - // Currency - if (isModEnabled('multicurrency')) { - print '\n"; - } - - // Multicurrency full amount - if (isModEnabled('multicurrency')) { - print ''; - - // Multicurrency Price - print ''; - - // Multicurrency remain to pay - print ''; - - print '"; - } - - // Full amount - print ''; - - // Received + already paid - print ''; - // Remain to take or to pay back + // Multicurrency Price print ''; - //$test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits)); - // Amount + // Multicurrency remain to pay + print ''; + 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_ttc += $objp->total_ttc; - $totalrecu += $paiement; - $totalrecucreditnote += $creditnotes; - $totalrecudeposits += $deposits; - $i++; } - if ($i > 1) { - // Print total - print ''; - print ''; - if (isModEnabled('multicurrency')) { - print ''; - print ''; - print ''; - print ''; - print ''; - } - print ''; - print ''; - print ''; - print ''; // Autofilled - print ''; - print "\n"; + // Full amount + print ''; + + // Received + already paid + print '
'.$arraytitle.''.$langs->trans('Date').''.$langs->trans('DateMaxPayment').''.$langs->trans('Currency').''.$langs->trans('MulticurrencyAmountTTC').''.$multicurrencyalreadypayedlabel.''.$multicurrencyremaindertopay.''.$langs->trans('MulticurrencyPaymentAmount').''.$langs->trans('AmountTTC').''.$alreadypayedlabel.''.$remaindertopay.''.$langs->trans('PaymentAmount').' 
'; + print $invoice->getNomUrl(1, ''); + if ($objp->socid != $facture->thirdparty->id) { + print ' - '.$soc->getNomUrl(1).' '; + } + print "'.dol_print_date($db->jdate($objp->df), 'day')."'; + print dol_print_date($db->jdate($objp->dlr), 'day'); + + if ($invoice->hasDelay()) { + print img_warning($langs->trans('Late')); } - $soc = new Societe($db); - $soc->fetch($objp->socid); + print ''.$objp->multicurrency_code."
'; - print $invoice->getNomUrl(1, ''); - if ($objp->socid != $facture->thirdparty->id) { - print ' - '.$soc->getNomUrl(1).' '; - } - print "'.dol_print_date($db->jdate($objp->df), 'day')."'; - print dol_print_date($db->jdate($objp->dlr), 'day'); - - if ($invoice->hasDelay()) { - print img_warning($langs->trans('Late')); - } - - print ''.$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 * (float) $multicurrency_remaintopay); - } - 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='AutoFillAmount' data-rowname='".$namef."' data-value='".($sign * (float) $multicurrency_remaintopay)."'"); - } - print ''; - print ''; - } else { - print ''; - print ''; - } - } - print "'.price($sign * $objp->total_ttc).''.price($sign * $paiement); - if ($creditnotes) { - print '+'.price($creditnotes).''; - } - if ($deposits) { - print '+'.price($deposits).''; + // Multicurrency full amount + if (isModEnabled('multicurrency')) { + print ''; + if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { + print '' . price($sign * $objp->multicurrency_total_ttc); } print ''; - print price($sign * (float) $remaintopay); - if (isModEnabled('prelevement')) { - $numdirectdebitopen = 0; - $totaldirectdebit = 0; - $sql = "SELECT COUNT(pfd.rowid) as nb, SUM(pfd.amount) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd"; - $sql .= " WHERE fk_facture = ".((int) $objp->facid); - $sql .= " AND pfd.traite = 0"; - $sql .= " AND pfd.ext_payment_id IS NULL"; - - $result_sql = $db->query($sql); - if ($result_sql) { - $obj = $db->fetch_object($result_sql); - $numdirectdebitopen = $obj->nb; - $totaldirectdebit = $obj->amount; - } else { - dol_print_error($db); + if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { + print price($sign * $multicurrency_payment); + if ($multicurrency_creditnotes) { + print '+'.price($multicurrency_creditnotes); } - if ($numdirectdebitopen) { - $langs->load("withdrawals"); - print img_warning($langs->trans("WarningSomeDirectDebitOrdersAlreadyExists", $numdirectdebitopen, price(price2num($totaldirectdebit, 'MT'), 0, $langs, 1, -1, -1, $conf->currency)), '', 'classfortooltip'); + if ($multicurrency_deposits) { + print '+'.price($multicurrency_deposits); } } print ''; + if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { + print price($sign * (float) $multicurrency_remaintopay); + } + print ''; - // Add remind amount - $namef = 'amount_'.$objp->facid; - $nameRemain = 'remain_'.$objp->facid; + // Add remind multicurrency amount + $namef = 'multicurrency_amount_'.$objp->facid; + $nameRemain = 'multicurrency_remain_'.$objp->facid; - if ($action != 'add_paiement') { - if (!empty($conf->use_javascript_ajax)) { - print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowname='".$namef."' data-value='".($sign * (float) $remaintopay)."'"); + 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='AutoFillAmount' data-rowname='".$namef."' data-value='".($sign * (float) $multicurrency_remaintopay)."'"); + } + print ''; + print ''; + } else { + print ''; + print ''; } - print ''; - print ''; - } else { - print ''; - print ''; } print "'; - //print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."
"; - if (!empty($amounts[$invoice->id]) && (abs((float) $amounts[$invoice->id]) > abs((float) $amountsresttopay[$invoice->id])) - || !empty($multicurrency_amounts[$invoice->id]) && (abs((float) $multicurrency_amounts[$invoice->id]) > abs((float) $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 * (float) price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).' 
'.price($sign * $objp->total_ttc).''.price($sign * $paiement); + if ($creditnotes) { + print '+'.price($creditnotes).''; } - print "
"; - print "
\n"; - } - $db->free($resql); - } else { - dol_print_error($db); - } - - $formconfirm = ''; - - // Save button - if ($action != 'add_paiement') { - $checkboxlabel = $langs->trans("ClosePaidInvoicesAutomatically"); - if ($facture->type == Facture::TYPE_CREDIT_NOTE) { - $checkboxlabel = $langs->trans("ClosePaidCreditNotesAutomatically"); - } - $buttontitle = $langs->trans('ToMakePayment'); - if ($facture->type == Facture::TYPE_CREDIT_NOTE) { - $buttontitle = $langs->trans('ToMakePaymentBack'); - } - - print '
'; - print ''; - /*if (isModEnabled('prelevement')) { - $langs->load("withdrawals"); - if (getDolGlobalString('WITHDRAW_DISABLE_AUTOCREATE_ONPAYMENTS')) { - print '
'.$langs->trans("IfInvoiceNeedOnWithdrawPaymentWontBeClosed"); + if ($deposits) { + print '+'.price($deposits).''; } - }*/ - print '


'; - print '
'; - } + print ''; - // Form to confirm payment - if ($action == 'add_paiement') { - $preselectedchoice = $addwarning ? 'no' : 'yes'; + // Remain to take or to pay back + print ''; + print price($sign * (float) $remaintopay); + if (isModEnabled('prelevement')) { + $numdirectdebitopen = 0; + $totaldirectdebit = 0; + $sql = "SELECT COUNT(pfd.rowid) as nb, SUM(pfd.amount) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd"; + $sql .= " WHERE fk_facture = ".((int) $objp->facid); + $sql .= " AND pfd.traite = 0"; + $sql .= " AND pfd.ext_payment_id IS NULL"; - print '
'; - $text = ''; - if (!empty($totalpayment)) { - $text = $langs->trans('ConfirmCustomerPayment', $totalpayment, $langs->transnoentitiesnoconv("Currency".$conf->currency)); + $result_sql = $db->query($sql); + if ($result_sql) { + $obj = $db->fetch_object($result_sql); + $numdirectdebitopen = $obj->nb; + $totaldirectdebit = $obj->amount; + } else { + dol_print_error($db); + } + if ($numdirectdebitopen) { + $langs->load("withdrawals"); + print img_warning($langs->trans("WarningSomeDirectDebitOrdersAlreadyExists", $numdirectdebitopen, price(price2num($totaldirectdebit, 'MT'), 0, $langs, 1, -1, -1, $conf->currency)), '', 'classfortooltip'); + } + } + print ''; + //$test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits)); + + // Amount + print ''; + + // 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='AutoFillAmount' data-rowname='".$namef."' data-value='".($sign * (float) $remaintopay)."'"); + } + print ''; + print ''; + } else { + print ''; + print ''; + } + print ""; + + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook + + // Warning + print ''; + //print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."
"; + if (!empty($amounts[$invoice->id]) && (abs((float) $amounts[$invoice->id]) > abs((float) $amountsresttopay[$invoice->id])) + || !empty($multicurrency_amounts[$invoice->id]) && (abs((float) $multicurrency_amounts[$invoice->id]) > abs((float) $multicurrency_amountsresttopay[$invoice->id]))) { + print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay")); + } + print ''; + + print "\n"; + + $total_ttc += $objp->total_ttc; + $totalrecu += $paiement; + $totalrecucreditnote += $creditnotes; + $totalrecudeposits += $deposits; + $i++; } - if (!empty($multicurrency_totalpayment)) { - $text .= '
'.$langs->trans('ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->transnoentitiesnoconv("paymentInInvoiceCurrency")); + + if ($i > 1) { + // Print total + print ''; + print ''.$langs->trans('TotalTTC').''; + if (isModEnabled('multicurrency')) { + print ''; + print ''; + print ''; + print ''; + print ''; + } + print ''.price($sign * $total_ttc).''; + print ''.price($sign * $totalrecu); + if ($totalrecucreditnote) { + print '+'.price($totalrecucreditnote); + } + if ($totalrecudeposits) { + print '+'.price($totalrecudeposits); + } + print ''; + print ''.price($sign * (float) price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).''; + print ''; // Autofilled + print ' '; + print "\n"; } - if (GETPOST('closepaidinvoices')) { - $text .= '
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); - print ''; - } - $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type, $langs->trans('ReceivedCustomersPayments'), $text, 'confirm_paiement', $formquestion, $preselectedchoice); + print ""; + print "
\n"; } - - // Call Hook formConfirm - $parameters = array('formConfirm' => $formconfirm); - $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) { - $formconfirm .= $hookmanager->resPrint; - } elseif ($reshook > 0) { - $formconfirm = $hookmanager->resPrint; - } - - // Print form confirm - print $formconfirm; - - print "
\n"; + $db->free($resql); + } else { + dol_print_error($db); } + + $formconfirm = ''; + + // Save button + if ($action != 'add_paiement') { + $checkboxlabel = $langs->trans("ClosePaidInvoicesAutomatically"); + if ($facture->type == Facture::TYPE_CREDIT_NOTE) { + $checkboxlabel = $langs->trans("ClosePaidCreditNotesAutomatically"); + } + $buttontitle = $langs->trans('ToMakePayment'); + if ($facture->type == Facture::TYPE_CREDIT_NOTE) { + $buttontitle = $langs->trans('ToMakePaymentBack'); + } + + print '
'; + print ''; + /*if (isModEnabled('prelevement')) { + $langs->load("withdrawals"); + if (getDolGlobalString('WITHDRAW_DISABLE_AUTOCREATE_ONPAYMENTS')) { + print '
'.$langs->trans("IfInvoiceNeedOnWithdrawPaymentWontBeClosed"); + } + }*/ + print '


'; + print '
'; + } + + // Form to confirm payment + if ($action == 'add_paiement') { + $preselectedchoice = $addwarning ? 'no' : 'yes'; + + print '
'; + $text = ''; + if (!empty($totalpayment)) { + $text = $langs->trans('ConfirmCustomerPayment', $totalpayment, $langs->transnoentitiesnoconv("Currency".$conf->currency)); + } + if (!empty($multicurrency_totalpayment)) { + $text .= '
'.$langs->trans('ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->transnoentitiesnoconv("paymentInInvoiceCurrency")); + } + if (GETPOST('closepaidinvoices')) { + $text .= '
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); + print ''; + } + $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type, $langs->trans('ReceivedCustomersPayments'), $text, 'confirm_paiement', $formquestion, $preselectedchoice); + } + + // Call Hook formConfirm + $parameters = array('formConfirm' => $formconfirm); + $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; + } elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; + } + + // Print form confirm + print $formconfirm; + + print "\n"; } -/** - * Show list of payments - */ -if (!GETPOST('action', 'aZ09')) { - if (empty($page) || $page == -1) { - $page = 0; - } - $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; - $offset = $limit * $page; - - if (!$sortorder) { - $sortorder = 'DESC'; - } - if (!$sortfield) { - $sortfield = 'p.datep'; - } - - $sql = 'SELECT p.datep as dp, p.amount, f.total_ttc as fa_amount, f.ref'; - $sql .= ', f.rowid as facid, c.libelle as paiement_type, p.num_paiement as num_payment'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id'; - $sql .= ', '.MAIN_DB_PREFIX.'facture as f'; - $sql .= ' WHERE p.fk_facture = f.rowid'; - $sql .= ' AND f.entity IN ('.getEntity('invoice').')'; - if ($socid) { - $sql .= ' AND f.fk_soc = '.((int) $socid); - } - - $sql .= $db->order($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"], 'f.ref', '', '', '', $sortfield, $sortorder); - print_liste_field_titre('Date', $_SERVER["PHP_SELF"], 'p.datep', '', '', '', $sortfield, $sortorder); - print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'c.libelle', '', '', '', $sortfield, $sortorder); - print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], 'p.amount', '', '', '', $sortfield, $sortorder, 'right '); - 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 ''; - print ''; - print ''; - - $parameters = array(); - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook - - $i++; - } - print '
'.$objp->ref."'.dol_print_date($db->jdate($objp->dp))."'.$objp->paiement_type.' '.$objp->num_payment."'.price($objp->amount).' 
'; - } -} - llxFooter(); $db->close();