浏览代码

MMIPayment : CB payment on propal and orders using MBIEtransactions, bank check & transfer

Mathieu Moulin 2 年之前
父节点
当前提交
71f2b3861a

+ 27 - 0
htdocs/comm/propal/card.php

@@ -2426,6 +2426,13 @@ if ($action == 'create') {
 	if (!empty($conf->margin->enabled)) {
 		$formmargin->displayMarginInfos($object);
 	}
+	
+	// Added by MMI Mathieu Moulin iProspective
+	$parameters = array();
+	$reshook = $hookmanager->executeHooks('doDisplayMoreInfos', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
+	if ($reshook < 0) {
+		setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+	}
 
 	print '</div>';
 	print '</div>';
@@ -2660,6 +2667,26 @@ if ($action == 'create') {
 			print showOnlineSignatureUrl('proposal', $object->ref).'<br>';
 		}
 
+		// Added by MMI Mathieu Moulin iProspective
+		// Show online payment link
+		$useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
+		if (!$useonlinepayment) {
+			$parameters = array();
+			$reshook = $hookmanager->executeHooks('addOnlinePaymentMeans', $parameters, $object, $action);
+			if ($reshook==0 && !empty($hookmanager->results['useonlinepayment']))
+				$useonlinepayment = true;
+		}
+
+		if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) {
+			$useonlinepayment = 0;
+		}
+
+		if ($object->statut != Propal::STATUS_DRAFT && $useonlinepayment) {
+			print '<br><!-- Link to pay -->';
+			require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
+			print showOnlinePaymentUrl('propal', $object->ref).'<br>';
+		}
+
 		print '</div><div class="fichehalfright"><div class="ficheaddleft">';
 
 		// List of actions on element

+ 15 - 1
htdocs/commande/card.php

@@ -2398,7 +2398,13 @@ if ($action == 'create' && $usercancreate) {
 		if (!empty($conf->margin->enabled)) {
 			$formmargin->displayMarginInfos($object);
 		}
-
+	
+		// Added by MMI Mathieu Moulin iProspective
+		$parameters = array();
+		$reshook = $hookmanager->executeHooks('doDisplayMoreInfos', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
+		if ($reshook < 0) {
+			setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+		}
 
 		print '</div>';
 		print '</div>';
@@ -2630,6 +2636,14 @@ if ($action == 'create' && $usercancreate) {
 
 			// Show online payment link
 			$useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
+			// Added by MMI Mathieu Moulin iProspective
+			if (!$useonlinepayment) {
+				$parameters = array();
+				$reshook = $hookmanager->executeHooks('addOnlinePaymentMeans', $parameters, $object, $action);
+				if ($reshook==0 && !empty($hookmanager->results['useonlinepayment']))
+					$useonlinepayment = true;
+			}
+			
 			if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) {
 				$useonlinepayment = 0;
 			}

+ 13 - 0
htdocs/compta/facture/card.php

@@ -1937,6 +1937,12 @@ if (empty($reshook)) {
 		// End of object creation, we show it
 		if ($id > 0 && !$error) {
 			$db->commit();
+			
+			// Added by MMI Mathieu Moulin iProspective
+			// For payment assignment
+			$parameters = array();
+			$reshook = $hookmanager->executeHooks('afterCreateAction', $parameters, $object, $action);
+			
 
 			// Define output language
 			if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && count($object->lines)) {
@@ -5587,6 +5593,13 @@ if ($action == 'create') {
 
 		// Show online payment link
 		$useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
+		// Added by MMI Mathieu Moulin iProspective
+		if (!$useonlinepayment) {
+			$parameters = array();
+			$reshook = $hookmanager->executeHooks('addOnlinePaymentMeans', $parameters, $object, $action);
+			if ($reshook==0 && !empty($hookmanager->results['useonlinepayment']))
+				$useonlinepayment = true;
+		}
 
 		if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
 			print '<br><!-- Link to pay -->'."\n";

+ 8 - 0
htdocs/compta/paiement/card.php

@@ -326,6 +326,10 @@ print '<tr><td class="tdtop">'.$form->editfieldkey("Comments", 'note', $object->
 print $form->editfieldval("Note", 'note', $object->note, $object, $user->rights->facture->paiement, 'textarea:'.ROWS_3.':90%');
 print '</td></tr>';
 
+// Added by MMI Mathieu Moulin iProspective
+$parameters = array();
+$reshook = $hookmanager->executeHooks('addMoreInformations', $parameters, $object, $action);
+
 print '</table>';
 
 print '</div>';
@@ -445,6 +449,10 @@ if ($resql) {
 
 print '<div class="tabsAction">';
 
+// Added by MMI Mathieu Moulin iProspective
+$parameters = array();
+$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
+
 if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
 	if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '') {
 		if ($user->rights->facture->paiement) {

+ 7 - 0
htdocs/compta/paiement/class/paiement.class.php

@@ -260,6 +260,13 @@ class Paiement extends CommonObject
 			}
 		}
 
+		// Added by MMI Mathieu Moulin iProspective
+		// MMIPayment for order & propal : Permit to specify only an amount
+		if (empty($amounts) && !empty($this->amount)) {
+			$totalamount = $this->amount;
+			$totalamount_converted = $this->amount;
+		}
+
 		$totalamount = price2num($totalamount);
 		$totalamount_converted = price2num($totalamount_converted);
 

+ 101 - 0
htdocs/core/class/commonobject.class.php

@@ -9319,4 +9319,105 @@ abstract class CommonObject
 		$this->db->commit();
 		return true;
 	}
+
+	/**
+	 * Get linked objects ids
+	 * @author MMI Mathieu Moulin iProspective
+	 *
+	 * @return Array
+	 */
+	public function fetchObjectLinkedIDs($object_class=true)
+	{
+		$classname = strtolower(get_class($this));
+
+		$sql = 'SELECT e.sourcetype object_type, e.fk_source fk_object
+			FROM '.MAIN_DB_PREFIX.'element_element e
+			WHERE e.targettype="'.$classname.'" AND e.fk_target="'.$this->id.'"
+			UNION
+			SELECT e.targettype object_type, e.fk_target fk_object
+			FROM '.MAIN_DB_PREFIX.'element_element e
+			WHERE e.sourcetype="'.$classname.'" AND e.fk_source="'.$this->id.'"';
+		//echo $sql;
+		$resql = $this->db->query($sql);
+		if (!$resql)
+			return;
+		$l = [];
+		while ($obj = $this->db->fetch_object($resql)) {
+			//var_dump($obj);
+			$l[] = [$obj->object_type, $obj->fk_object];
+		}
+
+		return $l;
+
+	}
+
+	/**
+	 * Get total amount already paid
+	 * @author MMI Mathieu Moulin iProspective
+	 *
+	 * @return []
+	 */
+	public function getPaiements()
+	{
+		$classname = strtolower(get_class($this));
+
+		$ol = $this->fetchObjectLinkedIDs();
+		//var_dump($ol);
+		if (!is_array($ol))
+			$ol = [];
+		$ol[] = [$classname, $this->id];
+
+		$sql_w = [];
+		foreach($ol as $o) {
+			if ($o[0]=='facture')
+				$sql_w[] = "(pf.`fk_facture`='".$o[1]."')";
+			$sql_w[] = "(po.`objecttype`='".$o[0]."' AND po.`fk_object`='".$o[1]."')";
+		}
+
+		$sql = "SELECT DISTINCT p2.*, p.*
+			FROM ".MAIN_DB_PREFIX."paiement p
+			LEFT JOIN ".MAIN_DB_PREFIX."paiement_extrafields p2 ON p2.fk_object=p.rowid
+			LEFT JOIN ".MAIN_DB_PREFIX."paiement_object po ON po.fk_paiement=p.rowid
+			LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture pf ON pf.fk_paiement=p.rowid
+			WHERE ".implode(' OR ', $sql_w);
+		//echo $sql;
+		$resql = $this->db->query($sql);
+		if (!$resql)
+			return;
+		$l = [];
+		while ($obj = $this->db->fetch_object($resql)) {
+			//var_dump($obj);
+			$l[$obj->rowid] = $obj;
+		}
+
+		return $l;
+	}
+	
+	/**
+	 * Get total amount already paid
+	 * @author MMI Mathieu Moulin iProspective
+	 *
+	 *	@return float
+	 */
+	public function getSommePaiement()
+	{
+		$mt = 0;
+		$l = $this->getPaiements();
+		foreach($l as $p) {
+			$mt += $p->amount;
+		}
+		//echo $mt;
+		return $mt;
+	}
+
+	/**
+	 * Get total amount already paid
+	 * @author MMI Mathieu Moulin iProspective
+	 *
+	 * @return float
+	 */
+	public function paye()
+	{
+		return $this->getSommePaiement() >= $this->total_ttc;
+	}
 }

+ 3 - 0
htdocs/core/class/html.formmail.class.php

@@ -852,6 +852,9 @@ class FormMail extends Form
 					require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
 					$langs->loadLangs(array('paypal', 'other'));
 					$typeforonlinepayment = 'free';
+					if ($this->param["models"] == 'propal' || $this->param["models"] == 'propal_send') {
+						$typeforonlinepayment = 'propal'; // TODO use detection on something else than template
+					}
 					if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') {
 						$typeforonlinepayment = 'order'; // TODO use detection on something else than template
 					}

+ 3 - 0
htdocs/core/lib/functions.lib.php

@@ -7163,6 +7163,9 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
 				require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
 				$outputlangs->loadLangs(array('paypal', 'other'));
 				$typeforonlinepayment = 'free';
+				if (is_object($object) && $object->element == 'propal') {
+					$typeforonlinepayment = 'propal';
+				}
 				if (is_object($object) && $object->element == 'commande') {
 					$typeforonlinepayment = 'order';
 				}

+ 35 - 3
htdocs/core/lib/payments.lib.php

@@ -133,7 +133,7 @@ function payment_supplier_prepare_head(Paiement $object)
  */
 function getValidOnlinePaymentMethods($paymentmethod = '')
 {
-	global $conf, $langs;
+	global $conf, $langs, $db;// @todo, $user;
 
 	$validpaymentmethod = array();
 
@@ -149,8 +149,16 @@ function getValidOnlinePaymentMethods($paymentmethod = '')
 		$langs->load("stripe");
 		$validpaymentmethod['stripe'] = 'valid';
 	}
+	// Added by MMI Mathieu Moulin iProspective
+	if ((empty($paymentmethod) || $paymentmethod == 'mbietransactions') && !empty($conf->mbietransactions->enabled)) {
+		$langs->load("mbietransactions@mbietransactions");
+		$validpaymentmethod['mbietransactions'] = 'valid';
+	}
 	// TODO Add trigger
-
+	//include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
+	//$interface = new Interfaces($db);
+	//$result = $interface->run_triggers('', NULL, $user, $langs, $conf);
+	//var_dump($validpaymentmethod);
 
 	return $validpaymentmethod;
 }
@@ -233,7 +241,31 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag
 			}
 		}
 		//if ($mode) $out.='&noidempotency=1';
-	} elseif ($type == 'order') {
+	// Added by MMI Mathieu Moulin iProspective
+	} elseif ($type == 'propal') {
+		$out = $urltouse.'/public/payment/newpayment.php?source=propal&ref='.($mode ? '<font color="#666666">' : '');
+		if ($mode == 1) {
+			$out .= 'propal_ref';
+		}
+		if ($mode == 0) {
+			$out .= urlencode($ref);
+		}
+		$out .= ($mode ? '</font>' : '');
+		if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
+			if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
+				$out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
+			} else {
+				$out .= '&securekey='.($mode ? '<font color="#666666">' : '');
+				if ($mode == 1) {
+					$out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + propal_ref)";
+				}
+				if ($mode == 0) {
+					$out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
+				}
+				$out .= ($mode ? '</font>' : '');
+			}
+		}
+	}  elseif ($type == 'order') {
 		$out = $urltouse.'/public/payment/newpayment.php?source=order&ref='.($mode ? '<font color="#666666">' : '');
 		if ($mode == 1) {
 			$out .= 'order_ref';

+ 23 - 0
htdocs/core/tpl/onlinepaymentlinks.tpl.php

@@ -30,6 +30,29 @@ print '<u>'.$langs->trans("FollowingUrlAreAvailableToMakePayments").':</u><br><b
 print img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlinePaymentOnFreeAmount", $servicename).':</span><br>';
 print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'free')."</strong><br><br>\n";
 
+// Added by MMI Mathieu Moulin iProspective
+if (!empty($conf->propal->enabled)) {
+	print '<div id="propal"></div>';
+	print img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlinePaymentOnPropal", $servicename).':</span><br>';
+	print '<strong class="wordbreak">'.getOnlinePaymentUrl(1, 'propal')."</strong><br>\n";
+	if (!empty($conf->global->PAYMENT_SECURITY_TOKEN) && !empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
+		$langs->load("propals");
+		print '<form action="'.$_SERVER["PHP_SELF"].'#order" method="POST">';
+		print '<input type="hidden" name="token" value="'.newToken().'">';
+
+		print $langs->trans("EnterRefToBuildUrl", $langs->transnoentitiesnoconv("Propal")).': ';
+		print '<input type="text class="flat" id="generate_propal_ref" name="generate_propal_ref" value="'.GETPOST('generate_propal_ref', 'alpha').'" size="10">';
+		print '<input type="submit" class="none reposition button smallpaddingimp" value="'.$langs->trans("GetSecuredUrl").'">';
+		if (GETPOST('generate_propal_ref', 'alpha')) {
+			print '<br> -> <strong class="wordbreak">';
+			$url = getOnlinePaymentUrl(0, 'propal', GETPOST('generate_propal_ref', 'alpha'));
+			print $url;
+			print "</strong><br>\n";
+		}
+		print '</form>';
+	}
+	print '<br>';
+}
 if (!empty($conf->commande->enabled)) {
 	print '<div id="order"></div>';
 	print img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder", $servicename).':</span><br>';

+ 1 - 0
htdocs/langs/fr_FR/main.lang

@@ -370,6 +370,7 @@ AmountInvoiced=Montant facturé
 AmountInvoicedHT=Montant facturé (HT)
 AmountInvoicedTTC=Montant facturé (TTC)
 AmountPayment=Montant paiement
+AmountAlreadyPaid=Montant déjà réglé
 AmountHTShort=Montant HT
 AmountTTCShort=Montant TTC
 AmountHT=Montant HT

+ 2 - 0
htdocs/langs/fr_FR/propal.lang

@@ -97,3 +97,5 @@ PropalAlreadyRefused=Proposition déjà refusée
 PropalSigned=Proposition acceptée
 PropalRefused=Proposition refusée
 ConfirmRefusePropal=Êtes-vous sûr de vouloir refuser cette proposition ?
+PaymentPropalRef=Paiement Proposition %s
+PropalPaid=Proposition commerciale déjà réglée

+ 197 - 27
htdocs/public/payment/newpayment.php

@@ -988,6 +988,151 @@ if (!$source) {
 }
 
 
+// Added by MMI Mathieu Moulin iProspective
+// Payment on customer propal
+if ($source == 'propal') {
+	$found = true;
+	$langs->load("propal");
+
+	require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
+
+	$propal = new Propal($db);
+	$result = $propal->fetch('', $ref);
+	if ($result <= 0) {
+		$mesg = $propal->error;
+		$error++;
+	} else {
+		$result = $propal->fetch_thirdparty($propal->socid);
+	}
+	$object = $propal;
+
+	if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
+		$dejaregle = $propal->getSommePaiement();
+		$amount = max(0, $propal->total_ttc - $dejaregle);
+		$paye = $propal->paye();
+		if (GETPOST("amount", 'alpha')) {
+			$amount = GETPOST("amount", 'alpha');
+		}
+		$amount = price2num($amount);
+	}
+
+	if (GETPOST('fulltag', 'alpha')) {
+		$fulltag = GETPOST('fulltag', 'alpha');
+	} else {
+		$fulltag = 'PRO='.$propal->id.'.CUS='.$propal->thirdparty->id;
+		if (!empty($TAG)) {
+			$tag = $TAG; $fulltag .= '.TAG='.$TAG;
+		}
+	}
+	$fulltag = dol_string_unaccent($fulltag);
+
+	// Creditor
+	print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
+	print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
+	print '<input type="hidden" name="creditor" value="'.$creditor.'">';
+	print '</td></tr>'."\n";
+
+	// Debitor
+	print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
+	print '</td><td class="CTableRow2"><b>'.$propal->thirdparty->name.'</b>';
+	print '</td></tr>'."\n";
+
+	// Object
+	$text = '<b>'.$langs->trans("PaymentPropalRef", $propal->ref).'</b>';
+	if (GETPOST('desc', 'alpha')) {
+		$text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
+	}
+	print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
+	print '</td><td class="CTableRow2">'.$text;
+	print '<input type="hidden" name="s" value="'.dol_escape_htmltag($source).'">';
+	print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($propal->ref).'">';
+	print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag($propal->id).'">';
+	$directdownloadlink = $propal->getLastMainDocLink('propal');
+	if ($directdownloadlink) {
+		print '<br><a href="'.$directdownloadlink.'" rel="nofollow noopener">';
+		print img_mime($propal->last_main_doc, '');
+		print $langs->trans("DownloadDocument").'</a>';
+	}
+	print '</td></tr>'."\n";
+
+	// MMI
+	if ($dejaregle) {
+		// Total
+		print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountTotal");
+		print '</td><td class="CTableRow2">';
+		print '<b>'.price2num($propal->total_ttc).'</b>';
+		print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+		print '</td></tr>'."\n";
+		// Déjà réglé
+		print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountAlreadyPaid");
+		print '</td><td class="CTableRow2">';
+		print '<b>'.price2num($dejaregle).'</b>';
+		print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+		print '</td></tr>'."\n";
+	}
+	
+	if (! $paye) {
+		// Amount
+		print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountPayment");
+		if (empty($amount)) {
+			print ' ('.$langs->trans("ToComplete").')';
+		}
+		print '</td><td class="CTableRow2">';
+		if (empty($amount) || !is_numeric($amount)) {
+			print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
+			print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
+		} else {
+			print '<b>'.price($amount).'</b>';
+			print '<input type="hidden" name="amount" value="'.$amount.'">';
+			print '<input type="hidden" name="newamount" value="'.$amount.'">';
+		}
+		// Currency
+		print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+		print '<input type="hidden" name="currency" value="'.$currency.'">';
+		print '</td></tr>'."\n";
+
+		// Tag
+		print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
+		print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
+		print '<input type="hidden" name="tag" value="'.dol_escape_htmltag($tag).'">';
+		print '<input type="hidden" name="fulltag" value="'.dol_escape_htmltag($fulltag).'">';
+		print '</td></tr>'."\n";
+	}
+
+	// Shipping address
+	$shipToName = $propal->thirdparty->name;
+	$shipToStreet = $propal->thirdparty->address;
+	$shipToCity = $propal->thirdparty->town;
+	$shipToState = $propal->thirdparty->state_code;
+	$shipToCountryCode = $propal->thirdparty->country_code;
+	$shipToZip = $propal->thirdparty->zip;
+	$shipToStreet2 = '';
+	$phoneNum = $propal->thirdparty->phone;
+	if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
+		print '<input type="hidden" name="shipToName" value="'.dol_escape_htmltag($shipToName).'">'."\n";
+		print '<input type="hidden" name="shipToStreet" value="'.dol_escape_htmltag($shipToStreet).'">'."\n";
+		print '<input type="hidden" name="shipToCity" value="'.dol_escape_htmltag($shipToCity).'">'."\n";
+		print '<input type="hidden" name="shipToState" value="'.dol_escape_htmltag($shipToState).'">'."\n";
+		print '<input type="hidden" name="shipToCountryCode" value="'.dol_escape_htmltag($shipToCountryCode).'">'."\n";
+		print '<input type="hidden" name="shipToZip" value="'.dol_escape_htmltag($shipToZip).'">'."\n";
+		print '<input type="hidden" name="shipToStreet2" value="'.dol_escape_htmltag($shipToStreet2).'">'."\n";
+		print '<input type="hidden" name="phoneNum" value="'.dol_escape_htmltag($phoneNum).'">'."\n";
+	} else {
+		print '<!-- Shipping address not complete, so we don t use it -->'."\n";
+	}
+	if (is_object($propal->thirdparty)) {
+		print '<input type="hidden" name="thirdparty_id" value="'.$propal->thirdparty->id.'">'."\n";
+	}
+	print '<input type="hidden" name="email" value="'.$propal->thirdparty->email.'">'."\n";
+	print '<input type="hidden" name="vatnumber" value="'.dol_escape_htmltag($propal->thirdparty->tva_intra).'">'."\n";
+	$labeldesc = $langs->trans("Propal").' '.$propal->ref;
+	if (GETPOST('desc', 'alpha')) {
+		$labeldesc = GETPOST('desc', 'alpha');
+	}
+	print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
+}
+
+
 // Payment on customer order
 if ($source == 'order') {
 	$found = true;
@@ -1006,7 +1151,10 @@ if ($source == 'order') {
 	$object = $order;
 
 	if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
-		$amount = $order->total_ttc;
+		// Added by MMI Mathieu Moulin iProspective
+		$dejaregle = $order->getSommePaiement();
+		$amount = max(0, $order->total_ttc - $dejaregle);
+		$paye = $order->paye();
 		if (GETPOST("amount", 'alpha')) {
 			$amount = GETPOST("amount", 'alpha');
 		}
@@ -1052,31 +1200,49 @@ if ($source == 'order') {
 	}
 	print '</td></tr>'."\n";
 
-	// Amount
-	print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
-	if (empty($amount)) {
-		print ' ('.$langs->trans("ToComplete").')';
-	}
-	print '</td><td class="CTableRow2">';
-	if (empty($amount) || !is_numeric($amount)) {
-		print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
-		print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
-	} else {
-		print '<b>'.price($amount).'</b>';
-		print '<input type="hidden" name="amount" value="'.$amount.'">';
-		print '<input type="hidden" name="newamount" value="'.$amount.'">';
+	// Added by MMI Mathieu Moulin iProspective
+	if ($dejaregle) {
+		// Total
+		print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountTotal");
+		print '</td><td class="CTableRow2">';
+		print '<b>'.price2num($order->total_ttc).'</b>';
+		print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+		print '</td></tr>'."\n";
+		// Déjà réglé
+		print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountAlreadyPaid");
+		print '</td><td class="CTableRow2">';
+		print '<b>'.price2num($dejaregle).'</b>';
+		print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+		print '</td></tr>'."\n";
 	}
-	// Currency
-	print ' <b>'.$langs->trans("Currency".$currency).'</b>';
-	print '<input type="hidden" name="currency" value="'.$currency.'">';
-	print '</td></tr>'."\n";
+	
+	if (! $paye) {
+		// Amount
+		print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountPayment");
+		if (empty($amount)) {
+			print ' ('.$langs->trans("ToComplete").')';
+		}
+		print '</td><td class="CTableRow2">';
+		if (empty($amount) || !is_numeric($amount)) {
+			print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
+			print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
+		} else {
+			print '<b>'.price($amount).'</b>';
+			print '<input type="hidden" name="amount" value="'.$amount.'">';
+			print '<input type="hidden" name="newamount" value="'.$amount.'">';
+		}
+		// Currency
+		print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+		print '<input type="hidden" name="currency" value="'.$currency.'">';
+		print '</td></tr>'."\n";
 
-	// Tag
-	print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
-	print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
-	print '<input type="hidden" name="tag" value="'.dol_escape_htmltag($tag).'">';
-	print '<input type="hidden" name="fulltag" value="'.dol_escape_htmltag($fulltag).'">';
-	print '</td></tr>'."\n";
+		// Tag
+		print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
+		print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
+		print '<input type="hidden" name="tag" value="'.dol_escape_htmltag($tag).'">';
+		print '<input type="hidden" name="fulltag" value="'.dol_escape_htmltag($fulltag).'">';
+		print '</td></tr>'."\n";
+	}
 
 	// Shipping address
 	$shipToName = $order->thirdparty->name;
@@ -1561,7 +1727,7 @@ if ($source == 'member' || $source == 'membersubscription') {
 				print '</td><td class="CTableRow2">';
 				print $form->selectarray("typeid", $adht->liste_array(1), $member->typeid, 0, 0, 0, 'onchange="window.location.replace(\''.$urlwithroot.'/public/payment/newpayment.php?source='.urlencode($source).'&ref='.urlencode($ref).'&amount='.urlencode($amount).'&typeid=\' + this.value + \'&securekey='.urlencode($SECUREKEY).'\');"', 0, 0, 0, '', '', 1);
 				print "</td></tr>\n";
-			} elseif ($action == dopayment) {
+			} elseif ($action == 'dopayment') {
 				print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("NewMemberType");
 				print '</td><td class="CTableRow2">'.dol_escape_htmltag($member->type);
 				print '<input type="hidden" name="membertypeid" value="'.$member->typeid.'">';
@@ -2026,7 +2192,10 @@ if ($action != 'dopayment') {
 			'object' => $object
 		];
 		$reshook = $hookmanager->executeHooks('doCheckStatus', $parameters, $object, $action);
-		if ($source == 'order' && $object->billed) {
+		// Added by MMI Mathieu Moulin iProspective
+		if ($source == 'propal' && $object->paye()) {
+			print '<br><br><span class="amountpaymentcomplete size15x">'.$langs->trans("PropalPaid").'</span>';
+		} elseif ($source == 'order' && $object->billed) {
 			print '<br><br><span class="amountpaymentcomplete size15x">'.$langs->trans("OrderBilled").'</span>';
 		} elseif ($source == 'invoice' && $object->paye) {
 			print '<br><br><span class="amountpaymentcomplete size15x">'.$langs->trans("InvoicePaid").'</span>';
@@ -2044,7 +2213,8 @@ if ($action != 'dopayment') {
 
 			// This hook is used to add Button to newpayment.php for external payment modules (ie Payzen, ...)
 			$parameters = [
-				'paymentmethod' => $paymentmethod
+				'paymentmethod' => $paymentmethod,
+				'amount' => price2num(GETPOST("amount", 'alpha')),
 			];
 			$reshook = $hookmanager->executeHooks('doAddButton', $parameters, $object, $action);
 			if ((empty($paymentmethod) || $paymentmethod == 'paybox') && !empty($conf->paybox->enabled)) {