diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index f2b26c73242..1d57f9c13d4 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -734,7 +734,7 @@ if (empty($reshook)) { } if (!$error) { - // On verifie si la facture a des paiements + // We check if invoice has payments $sql = 'SELECT pf.amount'; $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf'; $sql .= ' WHERE pf.fk_facture = '.((int) $object->id); @@ -984,7 +984,7 @@ if (empty($reshook)) { $db->rollback(); } } - } elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercancreate) { + } elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercanissuepayment) { // Delete payment $object->fetch($id); if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0) { diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 635727233d3..96d482b33ae 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -75,6 +75,12 @@ $hookmanager->initHooks(array('paiementcard', 'globalcard')); $formquestion = array(); +$usercanissuepayment = !empty($user->rights->facture->paiement); + +$fieldid = 'rowid'; +$isdraft = (($object->statut == Facture::STATUS_DRAFT) ? 1 : 0); +$result = restrictedArea($user, 'facture', $object->id, '', '', 'fk_soc', $fieldid, $isdraft); + /* * Actions @@ -87,7 +93,7 @@ if ($reshook < 0) { } if (empty($reshook)) { - if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes')) { + if (($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes')) && $usercanissuepayment) { $error = 0; $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); @@ -202,7 +208,7 @@ if (empty($reshook)) { /* * Action confirm_paiement */ - if ($action == 'confirm_paiement' && $confirm == 'yes') { + if ($action == 'confirm_paiement' && $confirm == 'yes' && $usercanissuepayment) { $error = 0; $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); @@ -486,7 +492,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''.$langs->trans('AccountToDebit').''; } print ''; - $form->select_comptes($accountid, 'accountid', 0, '', 2); + print $form->select_comptes($accountid, 'accountid', 0, '', 2, '', 0, '', 1); print ''; } else { print ' '; diff --git a/htdocs/compta/paiement/card.php b/htdocs/compta/paiement/card.php index 93fdd415513..8ff229f7ba7 100644 --- a/htdocs/compta/paiement/card.php +++ b/htdocs/compta/paiement/card.php @@ -64,6 +64,8 @@ if ($socid && $socid != $object->thirdparty->id) { accessforbidden(); } +$error = 0; + /* * Actions @@ -191,6 +193,39 @@ if ($action == 'setdatep' && !empty($_POST['datepday'])) { setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors'); } } +if ($action == 'createbankpayment' && !empty($user->rights->facture->paiement)) { + $db->begin(); + + // Create the record into bank for the amount of payment $object + if (!$error) { + $label = '(CustomerInvoicePayment)'; + if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) { + $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note + } + + $bankaccountid = GETPOST('accountid', 'int'); + if ($bankaccountid > 0) { + $object->paiementcode = $object->type_code; + $object->amounts = $object->getAmountsArray(); + + $result = $object->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', ''); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + } else { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors'); + $error++; + } + } + + + if (!$error) { + $db->commit(); + } else { + $db->rollback(); + } +} /* @@ -315,7 +350,37 @@ if (!empty($conf->banque->enabled)) { print $bankline->getNomUrl(1, 0, 'showconciliatedandaccounted'); } else { $langs->load("admin"); - print ''.$langs->trans("NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv("Module85Name")).''; + print ''; + print $langs->trans("NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv("Module85Name")); + print ''; + if (!empty($user->rights->facture->paiement)) { + // Try to guess $bankaccountidofinvoices that is ID of bank account defined on invoice. + // Return null if not found, return 0 if it has different value for at least 2 invoices, return the value if same on all invoices where a bank is defined. + $amountofpayments = $object->getAmountsArray(); + $bankaccountidofinvoices = null; + foreach ($amountofpayments as $idinvoice => $amountofpayment) { + $tmpinvoice = new Facture($db); + $tmpinvoice->fetch($idinvoice); + if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) { + if (is_null($bankaccountidofinvoices)) { + $bankaccountidofinvoices = $tmpinvoice->fk_account; + } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) { + $bankaccountidofinvoices = 0; + } + } + } + + print '
'; + print ''; + print ''; + print ''; + print ' '.$langs->trans("ToCreateRelatedRecordIntoBank").': '; + print $form->select_comptes($bankaccountidofinvoices, 'accountid', 0, '', 2, '', 0, '', 1); + //print ''; + print ''; + //print ''; + print '
'; + } } print ''; print ''; diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index ab68ac7f9b1..3abf38fb16e 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -951,6 +951,7 @@ class Paiement extends CommonObject * * @param string $filter Filter * @return int|array <0 if KO or array of invoice id + * @see getAmountsArray() */ public function getBillsArray($filter = '') { @@ -984,6 +985,7 @@ class Paiement extends CommonObject * Return list of amounts of payments. * * @return int|array Array of amount of payments + * @see getBillsArray() */ public function getAmountsArray() { diff --git a/htdocs/langs/en_US/banks.lang b/htdocs/langs/en_US/banks.lang index f066877f676..35ec6ac563b 100644 --- a/htdocs/langs/en_US/banks.lang +++ b/htdocs/langs/en_US/banks.lang @@ -182,3 +182,4 @@ IfYouDontReconcileDisableProperty=If you don't make the bank reconciliations on NoBankAccountDefined=No bank account defined NoRecordFoundIBankcAccount=No record found in bank account. Commonly, this occurs when a record has been deleted manually from the list of transaction in the bank account (for example during a reconciliation of the bank account). Another reason is that the payment was recorded when the module "%s" was disabled. AlreadyOneBankAccount=Already one bank account defined +ToCreateRelatedRecordIntoBank=To create missing related bank record \ No newline at end of file diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 8a5f8166106..9fb7783c345 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -41,6 +41,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php'; require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; + /** * Class to manage third parties objects (customers, suppliers, prospects...) */ @@ -2573,7 +2574,7 @@ class Societe extends CommonObject $name .= ' ('.$this->name_alias.')'; } - $result = ''; $label = ''; + $result = ''; $label = ''; $label2 = ''; $linkstart = ''; $linkend = ''; if (!empty($this->logo) && class_exists('Form')) { @@ -2641,47 +2642,48 @@ class Societe extends CommonObject } $label .= '
'.implode(' ', $phonelist); } + if (!empty($this->address)) { - $label .= '
'.$langs->trans("Address").': '.dol_format_address($this, 1, ' ', $langs); // Address + country + $label2 .= '
'.$langs->trans("Address").': '.dol_format_address($this, 1, ' ', $langs); // Address + country } elseif (!empty($this->country_code)) { - $label .= '
'.$langs->trans('Country').': '.$this->country_code; + $label2 .= '
'.$langs->trans('Country').': '.$this->country_code; } if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false)) { - $label .= '
'.$langs->trans('VATIntra').': '.dol_escape_htmltag($this->tva_intra); + $label2 .= '
'.$langs->trans('VATIntra').': '.dol_escape_htmltag($this->tva_intra); } if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) { if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) { - $label .= '
'.$langs->trans('ProfId1'.$this->country_code).': '.$this->idprof1; + $label2 .= '
'.$langs->trans('ProfId1'.$this->country_code).': '.$this->idprof1; } if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) { - $label .= '
'.$langs->trans('ProfId2'.$this->country_code).': '.$this->idprof2; + $label2 .= '
'.$langs->trans('ProfId2'.$this->country_code).': '.$this->idprof2; } if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) { - $label .= '
'.$langs->trans('ProfId3'.$this->country_code).': '.$this->idprof3; + $label2 .= '
'.$langs->trans('ProfId3'.$this->country_code).': '.$this->idprof3; } if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) { - $label .= '
'.$langs->trans('ProfId4'.$this->country_code).': '.$this->idprof4; + $label2 .= '
'.$langs->trans('ProfId4'.$this->country_code).': '.$this->idprof4; } if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) { - $label .= '
'.$langs->trans('ProfId5'.$this->country_code).': '.$this->idprof5; + $label2 .= '
'.$langs->trans('ProfId5'.$this->country_code).': '.$this->idprof5; } if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) { - $label .= '
'.$langs->trans('ProfId6'.$this->country_code).': '.$this->idprof6; + $label2 .= '
'.$langs->trans('ProfId6'.$this->country_code).': '.$this->idprof6; } } if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) { - $label .= '
'.$langs->trans('CustomerCode').': '.$this->code_client; + $label2 .= '
'.$langs->trans('CustomerCode').': '.$this->code_client; } if (!empty($this->code_fournisseur) && $this->fournisseur) { - $label .= '
'.$langs->trans('SupplierCode').': '.$this->code_fournisseur; + $label2 .= '
'.$langs->trans('SupplierCode').': '.$this->code_fournisseur; } if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3)) { - $label .= '
'.$langs->trans('CustomerAccountancyCode').': '.($this->code_compta ? $this->code_compta : $this->code_compta_client); + $label2 .= '
'.$langs->trans('CustomerAccountancyCode').': '.($this->code_compta ? $this->code_compta : $this->code_compta_client); } if (!empty($conf->accounting->enabled) && $this->fournisseur) { - $label .= '
'.$langs->trans('SupplierAccountancyCode').': '.$this->code_compta_fournisseur; + $label2 .= '
'.$langs->trans('SupplierAccountancyCode').': '.$this->code_compta_fournisseur; } - $label .= ''; + $label .= ($label2 ? '
'.$label2 : '').''; // Add type of canvas $linkstart .= (!empty($this->canvas) ? '&canvas='.$this->canvas : '');