Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop
This commit is contained in:
commit
257012aa19
@ -477,8 +477,9 @@ class Invoices extends DolibarrApi
|
||||
*
|
||||
* @param int $id Id of invoice to update
|
||||
* @param int $rowid Row key of the contact in the array contact_ids.
|
||||
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER).
|
||||
*
|
||||
* @url DELETE {id}/contact/{rowid}
|
||||
* @url DELETE {id}/contact/{rowid}/{type}
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
@ -486,7 +487,7 @@ class Invoices extends DolibarrApi
|
||||
* @throws RestException 404
|
||||
* @throws RestException 500
|
||||
*/
|
||||
public function deleteContact($id, $rowid)
|
||||
public function deleteContact($id, $rowid, $type)
|
||||
{
|
||||
if (!DolibarrApiAccess::$user->rights->facture->creer) {
|
||||
throw new RestException(401);
|
||||
@ -502,10 +503,17 @@ class Invoices extends DolibarrApi
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
$result = $this->invoice->delete_contact($rowid);
|
||||
if ($result < 0) {
|
||||
throw new RestException(500, 'Error when deleted the contact');
|
||||
}
|
||||
$contacts = $this->invoice->liste_contact();
|
||||
|
||||
foreach ($contacts as $contact) {
|
||||
if ($contact['id'] == $rowid && $contact['code'] == $type) {
|
||||
$result = $this->invoice->delete_contact($contact['rowid']);
|
||||
|
||||
if (!$result) {
|
||||
throw new RestException(500, 'Error when deleted the contact');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_cleanObjectDatas($this->invoice);
|
||||
}
|
||||
@ -1397,28 +1405,29 @@ class Invoices extends DolibarrApi
|
||||
/**
|
||||
* Add a payment to pay partially or completely one or several invoices.
|
||||
* Warning: Take care that all invoices are owned by the same customer.
|
||||
* Example of value for parameter arrayofamounts: {"1": "99.99", "2": "10"}
|
||||
* Example of value for parameter arrayofamounts: {"1": {"amount": "99.99", "multicurrency_amount": ""}, "2": {"amount": "", "multicurrency_amount": "10"}}
|
||||
*
|
||||
* @param array $arrayofamounts {@from body} Array with id of invoices with amount to pay for each invoice
|
||||
* @param string $datepaye {@from body} Payment date {@type timestamp}
|
||||
* @param int $paymentid {@from body} Payment mode Id {@min 1}
|
||||
* @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no}
|
||||
* @param int $accountid {@from body} Account Id {@min 1}
|
||||
* @param string $num_payment {@from body} Payment number (optional)
|
||||
* @param string $comment {@from body} Note private (optional)
|
||||
* @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ')
|
||||
* @param string $chqbank {@from body} Issuer bank name (optional)
|
||||
* @param int $paymentid {@from body} Payment mode Id {@min 1}
|
||||
* @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no}
|
||||
* @param int $accountid {@from body} Account Id {@min 1}
|
||||
* @param string $num_payment {@from body} Payment number (optional)
|
||||
* @param string $comment {@from body} Note private (optional)
|
||||
* @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ')
|
||||
* @param string $chqbank {@from body} Issuer bank name (optional)
|
||||
* @param string $ref_ext {@from body} External reference (optional)
|
||||
* @param bool $accepthigherpayment {@from body} Accept higher payments that it remains to be paid (optional)
|
||||
*
|
||||
* @url POST /paymentsdistributed
|
||||
*
|
||||
* @return int Payment ID
|
||||
*
|
||||
* @throws RestException 400
|
||||
* @throws RestException 401
|
||||
* @throws RestException 403
|
||||
* @throws RestException 404
|
||||
*/
|
||||
public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '')
|
||||
public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '', $ref_ext = '', $accepthigherpayment = false)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
@ -1451,7 +1460,7 @@ class Invoices extends DolibarrApi
|
||||
$multicurrency_amounts = array();
|
||||
|
||||
// Loop on each invoice to pay
|
||||
foreach ($arrayofamounts as $id => $amount)
|
||||
foreach ($arrayofamounts as $id => $amountarray)
|
||||
{
|
||||
$result = $this->invoice->fetch($id);
|
||||
if (!$result) {
|
||||
@ -1459,33 +1468,52 @@ class Invoices extends DolibarrApi
|
||||
throw new RestException(404, 'Invoice ID '.$id.' not found');
|
||||
}
|
||||
|
||||
// Calculate amount to pay
|
||||
$totalpaye = $this->invoice->getSommePaiement();
|
||||
$totalcreditnotes = $this->invoice->getSumCreditNotesUsed();
|
||||
$totaldeposits = $this->invoice->getSumDepositsUsed();
|
||||
$resteapayer = price2num($this->invoice->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
|
||||
if ($amount != 'remain')
|
||||
{
|
||||
if ($amount > $resteapayer)
|
||||
{
|
||||
$this->db->rollback();
|
||||
throw new RestException(400, 'Payment amount on invoice ID '.$id.' ('.$amount.') is higher than remain to pay ('.$resteapayer.')');
|
||||
}
|
||||
$resteapayer = $amount;
|
||||
if (($amountarray["amount"] == "remain" || $amountarray["amount"] > 0) && ($amountarray["multicurrency_amount"] == "remain" || $amountarray["multicurrency_amount"] > 0)) {
|
||||
$this->db->rollback();
|
||||
throw new RestException(400, 'Payment in both currency '.$id.' ( amount: '.$amountarray["amount"].', multicurrency_amount: '.$amountarray["multicurrency_amount"].')');
|
||||
}
|
||||
// Clean parameters amount if payment is for a credit note
|
||||
if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) {
|
||||
$resteapayer = price2num($resteapayer, 'MT');
|
||||
$amounts[$id] = -$resteapayer;
|
||||
|
||||
$is_multicurrency = 0;
|
||||
$total_ttc = $this->invoice->total_ttc;
|
||||
|
||||
if ($amountarray["multicurrency_amount"] > 0 || $amountarray["multicurrency_amount"] == "remain") {
|
||||
$is_multicurrency = 1;
|
||||
$total_ttc = $this->invoice->multicurrency_total_ttc;
|
||||
}
|
||||
|
||||
// Calculate amount to pay
|
||||
$totalpaye = $this->invoice->getSommePaiement($is_multicurrency);
|
||||
$totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency);
|
||||
$totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency);
|
||||
$remainstopay = $amount = price2num($total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
|
||||
|
||||
if (!$is_multicurrency && $amountarray["amount"] != 'remain')
|
||||
{
|
||||
$amount = price2num($amountarray["amount"], 'MT');
|
||||
}
|
||||
|
||||
if ($is_multicurrency && $amountarray["multicurrency_amount"] != 'remain')
|
||||
{
|
||||
$amount = price2num($amountarray["multicurrency_amount"], 'MT');
|
||||
}
|
||||
|
||||
if ($amount > $remainstopay && $accepthigherpayment == false) {
|
||||
$this->db->rollback();
|
||||
throw new RestException(400, 'Payment amount on invoice ID '.$id.' ('.$amount.') is higher than remain to pay ('.$remainstopay.')');
|
||||
}
|
||||
|
||||
if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) {
|
||||
$amount = -$amount;
|
||||
}
|
||||
|
||||
if ($is_multicurrency) {
|
||||
$amounts[$id] = null;
|
||||
// Multicurrency
|
||||
$newvalue = price2num($this->invoice->multicurrency_total_ttc, 'MT');
|
||||
$multicurrency_amounts[$id] = -$newvalue;
|
||||
$multicurrency_amounts[$id] = $amount;
|
||||
} else {
|
||||
$resteapayer = price2num($resteapayer, 'MT');
|
||||
$amounts[$id] = $resteapayer;
|
||||
$amounts[$id] = $amount;
|
||||
// Multicurrency
|
||||
$newvalue = price2num($this->invoice->multicurrency_total_ttc, 'MT');
|
||||
$multicurrency_amounts[$id] = $newvalue;
|
||||
$multicurrency_amounts[$id] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1498,7 +1526,7 @@ class Invoices extends DolibarrApi
|
||||
$paymentobj->paiementcode = dol_getIdFromCode($this->db, $paymentid, 'c_paiement', 'id', 'code', 1);
|
||||
$paymentobj->num_payment = $num_payment;
|
||||
$paymentobj->note_private = $comment;
|
||||
|
||||
$paymentobj->ref_ext = $ref_ext;
|
||||
$payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices
|
||||
if ($payment_id < 0)
|
||||
{
|
||||
|
||||
@ -44,6 +44,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
|
||||
$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant or multiple sales
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
$setterminal = GETPOST('setterminal', 'int');
|
||||
$setcurrency = GETPOST('setcurrency', 'aZ09');
|
||||
|
||||
if ($_SESSION["takeposterminal"] == "")
|
||||
{
|
||||
@ -57,6 +58,11 @@ if ($setterminal > 0)
|
||||
setcookie("takeposterminal", $setterminal, (time() + (86400 * 354)), '/', null, false, true); // Permanent takeposterminal var in a cookie
|
||||
}
|
||||
|
||||
if ($setcurrency!="")
|
||||
{
|
||||
$_SESSION["takeposcustomercurrency"] = $setcurrency;
|
||||
}
|
||||
|
||||
$_SESSION["urlfrom"] = '/takepos/index.php';
|
||||
|
||||
$langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter", "banks"));
|
||||
@ -725,14 +731,10 @@ function CashReport(rowid)
|
||||
$.colorbox({href:"../compta/cashcontrol/report.php?id="+rowid+"&contextpage=takepos", width:"60%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CashReport"); ?>"});
|
||||
}
|
||||
|
||||
// Popup to select the terminal to use
|
||||
function TerminalsDialog()
|
||||
// TakePOS Popup
|
||||
function ModalBox(ModalID)
|
||||
{
|
||||
var modal = document.getElementById("ModalTerminal");
|
||||
var span = document.getElementsByClassName("close")[0];
|
||||
span.onclick = function() {
|
||||
modal.style.display = "none";
|
||||
}
|
||||
var modal = document.getElementById(ModalID);
|
||||
modal.style.display = "block";
|
||||
}
|
||||
|
||||
@ -767,7 +769,7 @@ $( document ).ready(function() {
|
||||
//IF NO TERMINAL SELECTED
|
||||
if ($_SESSION["takeposterminal"] == "")
|
||||
{
|
||||
print "TerminalsDialog();";
|
||||
print "ModalBox('ModalTerminal');";
|
||||
}
|
||||
if ($conf->global->TAKEPOS_CONTROL_CASH_OPENING)
|
||||
{
|
||||
@ -798,7 +800,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
|
||||
<div class="topnav">
|
||||
<div class="topnav-left">
|
||||
<div class="inline-block valignmiddle">
|
||||
<a class="topnav-terminalhour" onclick="TerminalsDialog();">
|
||||
<a class="topnav-terminalhour" onclick="ModalBox('ModalTerminal');">
|
||||
<span class="fa fa-cash-register"></span>
|
||||
<span class="hideonsmartphone">
|
||||
<?php echo $langs->trans("Terminal"); ?>
|
||||
@ -808,7 +810,13 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
|
||||
else echo $_SESSION["takeposterminal"];
|
||||
echo '<span class="hideonsmartphone"> - '.dol_print_date(dol_now(), "day").'</span>';
|
||||
?>
|
||||
</a></div>
|
||||
</a>
|
||||
<?php
|
||||
if (!empty($conf->multicurrency->enabled)){
|
||||
print '<a class="valignmiddle tdoverflowmax100 minwidth75" id="multicurrency" onclick="ModalBox(\'ModalCurrency\');" title=""><span class="fas fa-coins paddingrightonly"></span>'.$langs->trans("Currency").'</a>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<!-- section for customer and open sales -->
|
||||
<div class="inline-block valignmiddle" id="customerandsales">
|
||||
</div>
|
||||
@ -841,7 +849,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
|
||||
<div id="ModalTerminal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<span class="close">×</span>
|
||||
<span class="close" href="#" onclick="document.getElementById('ModalTerminal').style.display = 'none';">×</span>
|
||||
<h3><?php print $langs->trans("TerminalSelect");?></h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@ -854,10 +862,30 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Modal multicurrency box -->
|
||||
<div id="ModalCurrency" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<span class="close" href="#" onclick="document.getElementById('ModalCurrency').style.display = 'none';">×</span>
|
||||
<h3><?php print $langs->trans("SetMultiCurrencyCode");?></h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<?php
|
||||
$sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency';
|
||||
$sql .= " WHERE entity IN ('".getEntity('mutlicurrency')."')";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
while ($obj = $db->fetch_object($resql))
|
||||
print '<button type="button" class="block" onclick="location.href=\'index.php?setcurrency='.$obj->code.'\'">'.$obj->code.'</button>';
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row1<?php if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) print 'withhead'; ?>">
|
||||
|
||||
|
||||
@ -1090,7 +1090,16 @@ if ($placeid > 0)
|
||||
}
|
||||
else $htmlforlines .= $line->qty;
|
||||
$htmlforlines .= '</td>';
|
||||
$htmlforlines .= '<td class="right classfortooltip" title="'.$moreinfo.'">'.price($line->total_ttc).'</td>';
|
||||
$htmlforlines .= '<td class="right classfortooltip" title="'.$moreinfo.'">';
|
||||
$htmlforlines .= price($line->total_ttc);
|
||||
if (!empty($conf->multicurrency->enabled) && $_SESSION["takeposcustomercurrency"]!="" && $conf->currency!=$_SESSION["takeposcustomercurrency"]) {
|
||||
//Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
|
||||
include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
|
||||
$multicurrency = new MultiCurrency($db);
|
||||
$multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
|
||||
$htmlforlines .= ' ('.price($line->total_ttc*$multicurrency->rate->rate).' '.$_SESSION["takeposcustomercurrency"].')';
|
||||
}
|
||||
$htmlforlines .= '</td>';
|
||||
}
|
||||
$htmlforlines .= '</tr>'."\n";
|
||||
$htmlforlines .= $htmlsupplements[$line->id];
|
||||
|
||||
@ -182,6 +182,16 @@ if ($conf->global->TAKEPOS_SHOW_CUSTOMER)
|
||||
<th class="right"><?php if ($gift!=1) echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n"; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
if (!empty($conf->multicurrency->enabled) && $_SESSION["takeposcustomercurrency"]!="" && $conf->currency!=$_SESSION["takeposcustomercurrency"]) {
|
||||
//Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
|
||||
include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
|
||||
$multicurrency = new MultiCurrency($db);
|
||||
$multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
|
||||
echo '<tr><th class="right">';
|
||||
if ($gift!=1) echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc*$multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
|
||||
echo '</td></tr>';
|
||||
}
|
||||
|
||||
if ($conf->global->TAKEPOS_PRINT_PAYMENT_METHOD) {
|
||||
$sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
|
||||
$sql .= " cp.code";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user