Debug v21
This commit is contained in:
parent
1814e2bf15
commit
6ff8e846ad
5 changed files with 133 additions and 54 deletions
|
|
@ -52,7 +52,7 @@ $backtopage = GETPOST('backtopage', 'alpha');
|
|||
$accountid = GETPOSTINT("accountid") > 0 ? GETPOSTINT("accountid") : 0;
|
||||
$label = GETPOST("label", "alpha");
|
||||
$sens = GETPOSTINT("sens");
|
||||
$amount = GETPOSTFLOAT("amount");
|
||||
$amount = GETPOST("amount");
|
||||
$paymenttype = GETPOST("paymenttype", "aZ09");
|
||||
$accountancy_code = GETPOST("accountancy_code", "alpha");
|
||||
$projectid = GETPOSTINT('projectid') ? GETPOSTINT('projectid') : GETPOSTINT('fk_project');
|
||||
|
|
@ -118,12 +118,14 @@ if (empty($reshook)) {
|
|||
}
|
||||
|
||||
$object->ref = ''; // TODO
|
||||
$object->accountid = GETPOSTINT("accountid") > 0 ? GETPOSTINT("accountid") : 0;
|
||||
$object->fk_account = GETPOSTINT("accountid") > 0 ? GETPOSTINT("accountid") : 0;
|
||||
$object->accountid = $object->fk_account;
|
||||
$object->datev = $datev;
|
||||
$object->datep = $datep;
|
||||
$object->amount = GETPOSTFLOAT("amount");
|
||||
$object->label = GETPOST("label", 'restricthtml');
|
||||
$object->note = GETPOST("note", 'restricthtml');
|
||||
$object->note_private = GETPOST("note", 'restricthtml');
|
||||
$object->note = $object->note_private;
|
||||
$object->type_payment = dol_getIdFromCode($db, GETPOST('paymenttype'), 'c_paiement', 'code', 'id', 1);
|
||||
$object->num_payment = GETPOST("num_payment", 'alpha');
|
||||
$object->chqemetteur = GETPOST("chqemetteur", 'alpha');
|
||||
|
|
@ -131,7 +133,7 @@ if (empty($reshook)) {
|
|||
$object->fk_user_author = $user->id;
|
||||
$object->category_transaction = GETPOSTINT("category_transaction");
|
||||
|
||||
$object->accountancy_code = GETPOST("accountancy_code") > 0 ? GETPOST("accountancy_code", "alpha") : "";
|
||||
$object->accountancy_code = (GETPOST("accountancy_code") != '-1' ? GETPOST("accountancy_code", "alpha") : "");
|
||||
$object->subledger_account = $subledger_account;
|
||||
|
||||
$object->sens = GETPOSTINT('sens');
|
||||
|
|
@ -168,6 +170,21 @@ if (empty($reshook)) {
|
|||
$error++;
|
||||
}
|
||||
|
||||
$bankaccount = new Account($db);
|
||||
$bankaccount->fetch($object->fk_account);
|
||||
|
||||
// Check currency
|
||||
$currencyofpayment = $conf->currency; // The currency of various payment is not yet asked, so we suppose it is the main company currency
|
||||
|
||||
//var_dump($currencyofpayment); var_dump($bankaccount->currency_code);
|
||||
|
||||
if (isModEnabled('multicurrency') && $currencyofpayment != $bankaccount->currency_code) {
|
||||
// TODO Support this feature the same way we do it for invoice payment
|
||||
// using the $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
|
||||
setEventMessages($langs->trans("ErrorVariousPaymentOnBankAccountWithADifferentCurrencyNotYetSupported"), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$db->begin();
|
||||
|
||||
|
|
@ -443,7 +460,7 @@ if ($action == 'create') {
|
|||
print '<tr><td>';
|
||||
print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
|
||||
print img_picto('', 'bank_account', 'class="pictofixedwidth"');
|
||||
print $form->select_comptes($accountid, "accountid", 0, '', 2, '', 0, '', 1); // Show list of main accounts (comptes courants)
|
||||
print $form->select_comptes($accountid, "accountid", 0, '', 2, '', (isModEnabled('multicurrency') ? 1 : 0), '', 1); // Show list of main accounts (comptes courants)
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
|
@ -473,6 +490,33 @@ if ($action == 'create') {
|
|||
print '<td><input id="chqbank" name="chqbank" size="30" type="text" value="'.GETPOST('chqbank', 'alphanohtml').'"></td></tr>';
|
||||
}
|
||||
|
||||
// Project
|
||||
if (isModEnabled('project')) {
|
||||
$formproject = new FormProjets($db);
|
||||
|
||||
// Associated project
|
||||
$langs->load("projects");
|
||||
|
||||
print '<tr><td>'.$langs->trans("Project").'</td><td>';
|
||||
print img_picto('', 'project', 'class="pictofixedwidth"');
|
||||
print $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// Other attributes
|
||||
$parameters = array();
|
||||
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
|
||||
// Category
|
||||
if (is_array($options) && count($options) && $conf->categorie->enabled) {
|
||||
print '<tr><td>'.$langs->trans("RubriquesTransactions").'</td><td>';
|
||||
print img_picto('', 'category').Form::selectarray('category_transaction', $options, GETPOST('category_transaction'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
print '<tr><td colspan="2"><hr></td></tr>';
|
||||
|
||||
// Accountancy account
|
||||
if (isModEnabled('accounting')) {
|
||||
// TODO Remove the fieldrequired and allow instead to edit a various payment to enter accounting code
|
||||
|
|
@ -510,31 +554,6 @@ if ($action == 'create') {
|
|||
print $form->selectarray('sens', $sensarray, $sens, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Project
|
||||
if (isModEnabled('project')) {
|
||||
$formproject = new FormProjets($db);
|
||||
|
||||
// Associated project
|
||||
$langs->load("projects");
|
||||
|
||||
print '<tr><td>'.$langs->trans("Project").'</td><td>';
|
||||
print img_picto('', 'bank_account', 'class="pictofixedwidth"');
|
||||
print $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// Other attributes
|
||||
$parameters = array();
|
||||
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
|
||||
// Category
|
||||
if (is_array($options) && count($options) && $conf->categorie->enabled) {
|
||||
print '<tr><td>'.$langs->trans("RubriquesTransactions").'</td><td>';
|
||||
print img_picto('', 'category').Form::selectarray('category_transaction', $options, GETPOST('category_transaction'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
print dol_get_fiche_end();
|
||||
|
|
|
|||
|
|
@ -780,12 +780,13 @@ while ($i < $imaxinloop) {
|
|||
|
||||
// Type
|
||||
if ($arrayfields['type']['checked']) {
|
||||
print '<td class="center">';
|
||||
$labeltoshow = '';
|
||||
if ($obj->payment_code) {
|
||||
print $langs->trans("PaymentTypeShort".$obj->payment_code);
|
||||
print ' ';
|
||||
$labeltoshow = $langs->transnoentitiesnoconv("PaymentTypeShort".$obj->payment_code).' ';
|
||||
}
|
||||
print $obj->num_payment;
|
||||
$labeltoshow .= $obj->num_payment;
|
||||
print '<td class="center tdoverflowmax150" title="'.dolPrintHTML($labeltoshow).'">';
|
||||
print $labeltoshow;
|
||||
print '</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
|
|
|
|||
|
|
@ -282,12 +282,18 @@ if (empty($reshook)) {
|
|||
$error++;
|
||||
}
|
||||
}
|
||||
/*
|
||||
var_dump($paiement->amount);
|
||||
var_dump($paiement->multicurrency_amount);
|
||||
var_dump($paiement->multicurrency_currency);
|
||||
*/
|
||||
|
||||
if (!$error) {
|
||||
$label = '(CustomerInvoicePayment)';
|
||||
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) {
|
||||
$label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
|
||||
}
|
||||
|
||||
$result = $paiement->addPaymentToBank($user, 'payment', $label, GETPOSTINT('accountid'), GETPOST('chqemetteur'), GETPOST('chqbank'));
|
||||
if ($result < 0) {
|
||||
setEventMessages($paiement->error, $paiement->errors, 'errors');
|
||||
|
|
@ -512,7 +518,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||
|
||||
print '<td>';
|
||||
print img_picto('', 'bank_account', 'class="pictofixedwidth"');
|
||||
print $form->select_comptes($accountid, 'accountid', 0, '', 2, '', 0, 'widthcentpercentminusx maxwidth500', 1);
|
||||
print $form->select_comptes($accountid, 'accountid', 0, '', 2, '', (isModEnabled('multicurrency') ? 1 : 0), 'widthcentpercentminusx maxwidth500', 1);
|
||||
print '</td>';
|
||||
} else {
|
||||
print '<td> </td>';
|
||||
|
|
@ -745,10 +751,10 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
|
|||
if (!empty($conf->use_javascript_ajax)) {
|
||||
print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowname='".$namef."' data-value='".($sign * (float) $multicurrency_remaintopay)."'");
|
||||
}
|
||||
print '<input type="text" class="maxwidth75 multicurrency_amount" name="'.$namef.'" value="'.GETPOST($namef).'">';
|
||||
print '<input type="text" class="maxwidth75 multicurrency_amount" name="'.$namef.'" value="'.(GETPOST($namef) != '0' ? GETPOST($namef) : '').'">';
|
||||
print '<input type="hidden" class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
|
||||
} else {
|
||||
print '<input type="text" class="maxwidth75" name="'.$namef.'_disabled" value="'.GETPOST($namef).'" disabled>';
|
||||
print '<input type="text" class="maxwidth75" name="'.$namef.'_disabled" value="'.(GETPOST($namef) != '0' ? GETPOST($namef) : '').'" disabled>';
|
||||
print '<input type="hidden" name="'.$namef.'" value="'.GETPOST($namef).'">';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,10 +98,15 @@ class Paiement extends CommonObject
|
|||
public $amount;
|
||||
|
||||
/**
|
||||
* @var float Total amount of payment (in the currency of the bank account)
|
||||
* @var float Total amount of payment (in the currency of the invoice/bank account)
|
||||
*/
|
||||
public $multicurrency_amount;
|
||||
|
||||
/**
|
||||
* @var string The currency of the total of payment (so the currency of the invoice/bank account)
|
||||
*/
|
||||
public $multicurrency_currency;
|
||||
|
||||
/**
|
||||
* @var array<float|string> array: invoice ID => amount for that invoice (in the main currency)
|
||||
*/
|
||||
|
|
@ -290,8 +295,9 @@ class Paiement extends CommonObject
|
|||
|
||||
/**
|
||||
* Create payment of invoices into database.
|
||||
* Use this->amounts to have list of invoices for the payment.
|
||||
* It uses this->amounts and ->multicurrency_amounts to get the list of detail of payment for each invoices for the payment.
|
||||
* For payment of a customer invoice, amounts are positive, for payment of credit note, amounts are negative
|
||||
* This will set also ->amount and ->multicurrency_amount at end.
|
||||
*
|
||||
* @param User $user Object user
|
||||
* @param int $closepaidinvoices 1=Also close paid invoices to paid, 0=Do nothing more
|
||||
|
|
@ -321,9 +327,10 @@ class Paiement extends CommonObject
|
|||
}
|
||||
|
||||
$currencyofpayment = '';
|
||||
$currencyofinvoices = '';
|
||||
$currencytxofpayment = '';
|
||||
|
||||
foreach ($amounts as $key => $value) { // How payment is dispatched
|
||||
foreach ($amounts as $key => $value) { // How payment is dispatched. $key is ID of invoice
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -335,18 +342,35 @@ class Paiement extends CommonObject
|
|||
$this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
|
||||
return -1;
|
||||
}
|
||||
if (empty($currencyofpayment)) {
|
||||
$currencyofpayment = isset($this->multicurrency_code[$key]) ? $this->multicurrency_code[$key] : "";
|
||||
} elseif ($currencyofpayment != $this->multicurrency_code[$key]) {
|
||||
|
||||
// Set the currency of the invoice
|
||||
$currencyofinvoiceforthisline = empty($this->multicurrency_code[$key]) ? $conf->currency : $this->multicurrency_code[$key];
|
||||
// If a payment was enter into section of foreign currency of invoice, we want to pay in the currency if invoice
|
||||
$currencyofpaymentforthisline = empty($this->multicurrency_amounts[$key]) ? $conf->currency : $this->multicurrency_code[$key];
|
||||
|
||||
//var_dump("Invoice ID: ".$key.", amount in company cur:".$this->amounts[$key]." amount in invoice cur:".$this->multicurrency_amounts[$key]." => currencyofinvoice= ".$currencyofinvoiceforthisline." - currencyofpaymentforthisline =".$currencyofpaymentforthisline);
|
||||
|
||||
if (empty($currencyofinvoices)) {
|
||||
$currencyofinvoices = $currencyofinvoiceforthisline;
|
||||
} elseif ($currencyofinvoices != $currencyofinvoiceforthisline) {
|
||||
// If we have invoices with different currencies in the payment, we stop here
|
||||
$this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (empty($currencyofpayment)) {
|
||||
$currencyofpayment = $currencyofpaymentforthisline;
|
||||
} elseif ($currencyofpayment != $currencyofpaymentforthisline) {
|
||||
// If we have invoices with different currencies in the payment, we stop here
|
||||
$this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (empty($currencytxofpayment)) {
|
||||
$currencytxofpayment = isset($this->multicurrency_tx[$key]) ? $this->multicurrency_tx[$key] : "";
|
||||
}
|
||||
|
||||
$totalamount_converted += $value_converted;
|
||||
$totalamount_converted += $value_converted; // Total in currency of the invoice
|
||||
$amounts_to_update[$key] = price2num($value_converted, 'MT');
|
||||
|
||||
$newvalue = price2num($value, 'MT');
|
||||
|
|
@ -355,6 +379,9 @@ class Paiement extends CommonObject
|
|||
if (!empty($newvalue)) {
|
||||
$atleastonepaymentnotnull++;
|
||||
}
|
||||
|
||||
//var_dump('currencytxofpayment = '.$currencytxofpayment." totalamount_converted =".$totalamount_converted);
|
||||
//print '<br>';
|
||||
}
|
||||
|
||||
if (empty($currencyofpayment)) { // Should not happen. For the case the multicurrency_code was not saved into invoices
|
||||
|
|
@ -367,14 +394,24 @@ class Paiement extends CommonObject
|
|||
$bankaccount = new Account($this->db);
|
||||
$bankaccount->fetch($this->fk_account);
|
||||
$bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
|
||||
if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
|
||||
$langs->load("errors");
|
||||
$this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
|
||||
return -1;
|
||||
|
||||
if ($bankcurrencycode != $conf->currency) {
|
||||
// If we try to pay on a bank with a different currency
|
||||
if ($bankcurrencycode != $currencyofinvoices && $currencyofinvoices != $conf->currency) {
|
||||
$langs->load("errors");
|
||||
$this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofinvoices, $bankcurrencycode);
|
||||
return -1;
|
||||
}
|
||||
if ($bankcurrencycode != $currencyofpayment && $currencyofpayment != $conf->currency) {
|
||||
$langs->load("errors");
|
||||
$this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
// No problem in this case
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$totalamount = (float) price2num($totalamount);
|
||||
$totalamount_converted = (float) price2num($totalamount_converted);
|
||||
|
||||
|
|
@ -603,9 +640,12 @@ class Paiement extends CommonObject
|
|||
}
|
||||
|
||||
if (!$error) {
|
||||
// Set some properties that may be used by other process after calling the create
|
||||
$this->amount = $total;
|
||||
$this->total = $total; // deprecated
|
||||
$this->multicurrency_amount = $mtotal;
|
||||
$this->multicurrency_currency = $currencyofinvoices;
|
||||
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
} else {
|
||||
|
|
@ -626,8 +666,6 @@ class Paiement extends CommonObject
|
|||
*/
|
||||
public function delete($user, $notrigger = 0)
|
||||
{
|
||||
$error = 0;
|
||||
|
||||
$bank_line_id = $this->bank_line;
|
||||
|
||||
$this->db->begin();
|
||||
|
|
@ -730,6 +768,9 @@ class Paiement extends CommonObject
|
|||
$error = 0;
|
||||
$bank_line_id = 0;
|
||||
|
||||
// Note: ->amount (amount in company currency) ant multicurrency_amount (amount in )was set by the ->create beforecalling this.
|
||||
// The create had also checked that currency of payment is same than currency of bank account
|
||||
|
||||
if (isModEnabled("bank")) {
|
||||
if ($accountid <= 0) {
|
||||
$this->error = 'Bad value for parameter accountid='.$accountid;
|
||||
|
|
@ -759,9 +800,20 @@ class Paiement extends CommonObject
|
|||
$totalamount = $this->total; // For backward compatibility
|
||||
}
|
||||
|
||||
// if dolibarr currency != bank currency then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me)
|
||||
if (isModEnabled('multicurrency') && $conf->currency != $acc->currency_code) {
|
||||
$totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency
|
||||
// this->amount is amount of payment in company currency
|
||||
// this->multicurrency_amount of payment in other currency
|
||||
// this->multicurrency_currency is the currency of the payment (may be same than the company one)
|
||||
if ($this->multicurrency_currency == $conf->currency) {
|
||||
if ($this->amount != $this->multicurrency_amount) {
|
||||
// Add protection, should not happen
|
||||
$error++;
|
||||
$this->error = 'Payment in same currency than company but this->amount != this->multicurrency_amount';
|
||||
}
|
||||
}
|
||||
|
||||
// if company currency != bank currency, then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me)
|
||||
if ($conf->currency != $acc->currency_code) {
|
||||
$totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency of invoice
|
||||
$totalamount_main_currency = $this->amount; // We will also save the amount in main currency into column llx_bank.amount_main_currency
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -344,6 +344,7 @@ ErrorStartHourIsNull=Start date field cannot be empty
|
|||
ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter=Too many lines to process. Please use a more selective filter.
|
||||
ErrorEmptyValueForQty=Quantity cannot be zero.
|
||||
ErrorQtyOrderedLessQtyShipped = The quantity ordered cannot be less than the quantity shipped.
|
||||
ErrorVariousPaymentOnBankAccountWithADifferentCurrencyNotYetSupported=Error, creating a various payment on a bank account with a currency different than the currency of the company is not yet supported.
|
||||
# Warnings
|
||||
WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup.
|
||||
WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user.
|
||||
|
|
|
|||
Loading…
Reference in a new issue