From 08b9e054251fb8f05de6173ca1f71e90467547b6 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 21 Sep 2014 17:42:38 +0200 Subject: [PATCH 01/24] New Module : Manage Financial Loan --- htdocs/admin/loan.php | 119 ++++ htdocs/compta/loan/card.php | 467 ++++++++++++++ htdocs/compta/loan/class/index.html | 0 htdocs/compta/loan/class/loan.class.php | 477 ++++++++++++++ .../compta/loan/class/paymentloan.class.php | 603 ++++++++++++++++++ htdocs/compta/loan/document.php | 178 ++++++ htdocs/compta/loan/index.html | 0 htdocs/compta/loan/index.php | 208 ++++++ htdocs/compta/loan/info.php | 65 ++ htdocs/core/lib/loan.lib.php | 66 ++ htdocs/core/menus/standard/eldy.lib.php | 19 +- htdocs/core/modules/modLoan.class.php | 173 +++++ htdocs/install/mysql/tables/llx_loan.sql | 47 ++ .../install/mysql/tables/llx_payment_loan.sql | 33 + 14 files changed, 2450 insertions(+), 5 deletions(-) create mode 100644 htdocs/admin/loan.php create mode 100644 htdocs/compta/loan/card.php create mode 100644 htdocs/compta/loan/class/index.html create mode 100644 htdocs/compta/loan/class/loan.class.php create mode 100644 htdocs/compta/loan/class/paymentloan.class.php create mode 100644 htdocs/compta/loan/document.php create mode 100644 htdocs/compta/loan/index.html create mode 100644 htdocs/compta/loan/index.php create mode 100644 htdocs/compta/loan/info.php create mode 100644 htdocs/core/lib/loan.lib.php create mode 100644 htdocs/core/modules/modLoan.class.php create mode 100644 htdocs/install/mysql/tables/llx_loan.sql create mode 100644 htdocs/install/mysql/tables/llx_payment_loan.sql diff --git a/htdocs/admin/loan.php b/htdocs/admin/loan.php new file mode 100644 index 00000000000..4cd22ef2c8c --- /dev/null +++ b/htdocs/admin/loan.php @@ -0,0 +1,119 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * \file htdocs/admin/loan.php + * \ingroup loan + * \brief Setup page to configure loan module + */ + +require '../main.inc.php'; + +// Class +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; + +$langs->load("admin"); +$langs->load("loan"); + +// Security check +if (!$user->admin) + accessforbidden(); + +$action = GETPOST('action', 'alpha'); + +// Other parameters LOAN_* +$list = array ( + 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL', + 'LOAN_ACCOUNTING_ACCOUNT_INTEREST', + 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE' +); + +/* + * Actions + */ + +if ($action == 'update') +{ + $error = 0; + + foreach ($list as $constname) { + $constvalue = GETPOST($constname, 'alpha'); + + if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { + $error++; + } + } + + if (! $error) + { + setEventMessage($langs->trans("SetupSaved")); + } + else + { + setEventMessage($langs->trans("Error"),'errors'); + } +} + +/* + * View + */ + +llxHeader(); + +$form = new Form($db); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans('ConfigLoan'),$linkback,'setup'); + +print '
'; +print ''; +print ''; + +/* + * Params + */ +print ''; +print ''; +print ''; +print "\n"; + +foreach ($list as $key) +{ + $var=!$var; + + print ''; + + // Param + $label = $langs->trans($key); + print ''; + + // Value + print ''; +} + +print ''; + +print ''; +print "
' . $langs->trans('Options') . '
'; + print ''; + print '
\n"; + +print '
'; + +llxFooter(); +$db->close(); \ No newline at end of file diff --git a/htdocs/compta/loan/card.php b/htdocs/compta/loan/card.php new file mode 100644 index 00000000000..f8cf4d29327 --- /dev/null +++ b/htdocs/compta/loan/card.php @@ -0,0 +1,467 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/loan/card.php + * \ingroup loan + * \brief Loan card + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; + +$langs->load("compta"); +$langs->load("bills"); +$langs->load("loan"); + +$id=GETPOST('id','int'); +$action=GETPOST("action"); +$confirm=GETPOST('confirm'); + +// Security check +$socid = GETPOST('socid','int'); +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'loan', $id, '',''); + +/* + * Actions + */ + +// Classify paid +if ($action == 'confirm_paid' && $confirm == 'yes') +{ + $loan = new Loan($db); + $loan->fetch($id); + $result = $loan->set_paid($user); +} + +// Delete loan +if ($action == 'confirm_delete' && $confirm == 'yes') +{ + $loan = new Loan($db); + $loan->fetch($id); + $result=$loan->delete($user); + if ($result > 0) + { + header("Location: index.php"); + exit; + } + else + { + setEventMessage($loan->error, 'errors'); + } +} + + +// Add loan +if ($action == 'add' && $user->rights->loan->write) +{ + $dateech=@dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]); + $dateperiod=@dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]); + if (! $dateech) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors'); + $action = 'create'; + } + elseif (! $dateperiod) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors'); + $action = 'create'; + } + elseif (! $_POST["capital"]) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Capital")), 'errors'); + $action = 'create'; + } + else + { + $loan = new Loan($db); + + $loan->label = $_POST["label"]; + $loan->date_ech = $dateech; + $loan->periode = $dateperiod; + $loan->capital = $_POST["capital"]; + + $id=$loan->create($user); + if ($id <= 0) + { + setEventMessage($loan->error, 'errors'); + } + } +} + + +if ($action == 'update' && ! $_POST["cancel"] && $user->rights->loan->write) +{ + $dateech=dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]); + $dateperiod=dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]); + if (! $dateech) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors'); + $action = 'edit'; + } + elseif (! $dateperiod) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors'); + $action = 'edit'; + } + else + { + $loan = new Loan($db); + $result=$loan->fetch($_GET["id"]); + + $loan->lib=$_POST["label"]; + $loan->date_ech=$dateech; + $loan->periode=$dateperiod; + + $result=$loan->update($user); + if ($result <= 0) + { + setEventMessage($loan->error, 'errors'); + } + } +} + + + +/* + * View + */ + +$form = new Form($db); + +$help_url='EN:Module_Loan|FR:Module Emprunt'; +llxHeader("",$langs->trans("Loan"),$help_url); + + +// Create mode +if ($action == 'create') +{ + //WYSIWYG Editor + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + + print_fiche_titre($langs->trans("NewLoan")); + + $datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int')); + + print '
' . "\n"; + print ''; + print ''; + + print ''; + + // Label + print ''; + + // Bank account + if (! empty($conf->banque->enabled)) + { + print ''; + } + else + { + print ''; + } + + // Capital + print ''; + + // Date Start + print ""; + print ''; + + // Date End + print ""; + print ''; + + // Number of terms + print ''; + + // Rate + print ''; + + // Note + print ''; + print ''; + print ''; + print '
'.$langs->trans("Label").'
'.$langs->trans("Account").''; + $form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Show list of bank account with courant + print '
'.$langs->trans("Account").''; + print $langs->trans("NoBankAccountDefined"); + print '
'.$langs->trans("Capital").'
'.$langs->trans("DateStart").''; + print $form->select_date($datestart?$datestart:-1,'','','','','add',1,1); + print '
'.$langs->trans("DateEnd").''; + print $form->select_date($dateend?$dateend:-1,'','','','','add',1,1); + print '
'.$langs->trans("Nbterms").'
'.$langs->trans("Rate").'
'.$langs->trans('Note').''; + + $doleditor = new DolEditor('note', GETPOST('note', 'alpha'), '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, 100); + print $doleditor->Create(1); + + print '
'; + + print '
'; + + // Accountancy + print ''; + + if ($conf->accounting->enabled) + { + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + } + else + { + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + } + + print '
'.$langs->trans("LoanAccountancyCapitalCode").''; + print '
'.$langs->trans("LoanAccountancyInsuranceCode").''; + print '
'.$langs->trans("LoanAccountancyInterestCode").''; + print '
'.$langs->trans("LoanAccountancyCapitalCode").''; + print '
'.$langs->trans("LoanAccountancyInsuranceCode").''; + print '
'.$langs->trans("LoanAccountancyInterestCode").''; + print '
'; + + print '
    '; + print ''; +} + +// View +if ($id > 0) +{ + $object = new Loan($db); + $result=$object->fetch($id); + + if ($result > 0) + { + $head=loan_prepare_head($object); + + dol_fiche_head($head, 'card', $langs->trans("Loan"),0,'bill'); + + // Confirm for loan + if ($action == 'paid') + { + $text=$langs->trans('ConfirmPayLoan'); + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans('PayLoan'),$text,"confirm_paid",'','',2); + } + + if ($action == 'delete') + { + $text=$langs->trans('ConfirmDeleteLoan'); + print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteLoan'),$text,'confirm_delete','','',2); + } + + if ($action == 'edit') + { + print "id&action=update\" method=\"post\">"; + print ''; + } + + print ''; + + // Ref + print '"; + + // Label + if ($action == 'edit') + { + print ''; + } + else + { + print ''; + } + + $rowspan=5; + print '"; + + print ""; + + // Period end date + print ""; + print ""; + + // Due date + if ($action == 'edit') + { + print '"; + } + else { + print ""; + } + + // Amount + print ''; + + // Status + print ''; + + print '
'.$langs->trans("Ref").''; + print $form->showrefnav($object,'id'); + print "
'.$langs->trans("Label").''; + print ''; + print '
'.$langs->trans("Label").''.$object->label.'
'; + + /* + * Payments + */ + $sql = "SELECT p.rowid, p.num_payment, datep as dp, p.amount,"; + $sql.= "c.libelle as paiement_type"; + $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; + $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; + $sql.= ", ".MAIN_DB_PREFIX."loan as l"; + $sql.= " WHERE p.fk_loan = ".$id; + $sql.= " AND p.fk_loan = l.rowid"; + $sql.= " AND l.entity = ".$conf->entity; + $sql.= " AND p.fk_typepayment = c.id"; + $sql.= " ORDER BY dp DESC"; + + //print $sql; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; $total = 0; + echo ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + print "'; + print '\n"; + print "\n"; + print '\n"; + print ""; + $totalpaye += $objp->amount; + $i++; + } + + if ($object->paye == 0) + { + print "\n"; + print "\n"; + + $resteapayer = $object->amount - $totalpaye; + + print ""; + print "\n"; + } + print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; + print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$objp->paiement_type.' '.$objp->num_paiement."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaye)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("RemainderToPay")." :".price($resteapayer)." ".$langs->trans("Currency".$conf->currency)."
"; + $db->free($resql); + } + else + { + dol_print_error($db); + } + print "
".$langs->trans("PeriodEndDate").""; + if ($action == 'edit') + { + print $form->select_date($object->periode, 'period', 0, 0, 0, 'charge', 1); + } + else + { + print dol_print_date($object->periode,"day"); + } + print "
'.$langs->trans("DateDue").""; + print $form->select_date($object->date_ech, 'ech', 0, 0, 0, 'charge', 1); + print "
".$langs->trans("DateDue")."".dol_print_date($object->date_ech,'day')."
'.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Status").''.$object->getLibStatut(4, $totalpaye).'
'; + + if ($action == 'edit') + { + print '
'; + print ''; + print '   '; + print ''; + print '\n"; + + dol_fiche_end(); + + + /* + * Boutons actions + */ + if ($action != 'edit') + { + print "
\n"; + + // Edit + if ($user->rights->loan->write) + { + print "id&action=edit\">".$langs->trans("Modify").""; + } + + // Emettre paiement + if ($object->paye == 0 && ((price2num($object->amount) < 0 && round($resteapayer) < 0) || (price2num($object->amount) > 0 && round($resteapayer) > 0)) && $user->rights->loan->write) + { + print "id&action=create\">".$langs->trans("DoPayment").""; + } + + // Classify 'paid' + if ($object->paye == 0 && round($resteapayer) <=0 && $user->rights->loan->write) + { + print "id&action=paid\">".$langs->trans("ClassifyPaid").""; + } + + // Delete + if ($user->rights->loan->delete) + { + print "id&action=delete\">".$langs->trans("Delete").""; + } + + print "
"; + } + } + else + { + // Loan not find + dol_print_error('',$object->error); + } +} + + +llxFooter(); + +$db->close(); diff --git a/htdocs/compta/loan/class/index.html b/htdocs/compta/loan/class/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/compta/loan/class/loan.class.php b/htdocs/compta/loan/class/loan.class.php new file mode 100644 index 00000000000..74aed1d048b --- /dev/null +++ b/htdocs/compta/loan/class/loan.class.php @@ -0,0 +1,477 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/loan/class/loan.class.php + * \ingroup loan + * \brief Class for loan module + */ +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; + + +/** \class Loan + * \brief Class to manage loan + */ +class Loan extends CommonObject +{ + public $element='loan'; + public $table='loan'; + public $table_element='loan'; + + var $id; + var $ref; + var $date_start; + var $dateend; + var $label; + var $capital; + var $nbterm; + var $rate; + var $note; + var $account_capital; + var $account_insurance; + var $account_interest; + var $date_creation; + var $date_modification; + var $date_validation; + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + $this->db = $db; + return 1; + } + + /** + * Load object in memory from database + * + * @param int $id id object + * @return void + */ + function fetch($id) + { + $sql = "SELECT l.rowid, l.datestart,"; + $sql.= " l.label, l.capital"; + $sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; + $sql.= " WHERE l.rowid = ".$id; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->datestart = $this->db->jdate($obj->datestart); + $this->label = $obj->label; + $this->capital = $obj->capital; + + return 1; + } + else + { + return 0; + } + $this->db->free($resql); + } + else + { + $this->error=$this->db->lasterror(); + return -1; + } + } + + + /** + * Create a social contribution into database + * + * @param User $user User making creation + * @return int <0 if KO, id if OK + */ + function create($user) + { + global $conf; + + // clean parameters + $newcapital=price2num($this->capital,'MT'); + + // Validation parametres + if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode)) + { + $this->error="ErrorBadParameter"; + return -2; + } + + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount, entity)"; + $sql.= " VALUES (".$this->type.",'".$this->db->escape($this->lib)."',"; + $sql.= " '".$this->db->idate($this->date_ech)."','".$this->db->idate($this->periode)."',"; + $sql.= " '".price2num($newamount)."',"; + $sql.= " ".$conf->entity; + $sql.= ")"; + + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales"); + + //dol_syslog("ChargesSociales::create this->id=".$this->id); + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + } + + + /** + * Delete a social contribution + * + * @param User $user Object user making delete + * @return int <0 if KO, >0 if OK + */ + function delete($user) + { + $error=0; + + $this->db->begin(); + + // Get bank transaction lines for this social contributions + include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + $account=new Account($this->db); + $lines_url=$account->get_url('',$this->id,'sc'); + + // Delete bank urls + foreach ($lines_url as $line_url) + { + if (! $error) + { + $accountline=new AccountLine($this->db); + $accountline->fetch($line_url['fk_bank']); + $result=$accountline->delete_urls($user); + if ($result < 0) + { + $error++; + } + } + } + + // Delete payments + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge where fk_charge='".$this->id."'"; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) + { + $error++; + $this->error=$this->db->lasterror(); + } + } + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales where rowid='".$this->id."'"; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) + { + $error++; + $this->error=$this->db->lasterror(); + } + } + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + + } + + + /** + * Met a jour une charge sociale + * + * @param User $user Utilisateur qui modifie + * @return int <0 si erreur, >0 si ok + */ + function update($user) + { + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales"; + $sql.= " SET libelle='".$this->db->escape($this->lib)."',"; + $sql.= " date_ech='".$this->db->idate($this->date_ech)."',"; + $sql.= " periode='".$this->db->idate($this->periode)."'"; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + } + + /** + * Enter description here ... + * + * @param int $year Year + * @return number + */ + function solde($year = 0) + { + global $conf; + + $sql = "SELECT SUM(f.amount) as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as f"; + $sql.= " WHERE f.entity = ".$conf->entity; + $sql.= " AND paye = 0"; + + if ($year) { + $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' "; + } + + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + return $obj->amount; + } + else + { + return 0; + } + + $this->db->free($result); + + } + else + { + print $this->db->error(); + return -1; + } + } + + /** + * Tag social contribution as payed completely + * + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK + */ + function set_paid($user) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET"; + $sql.= " paye = 1"; + $sql.= " WHERE rowid = ".$this->id; + $return = $this->db->query($sql); + if ($return) return 1; + else return -1; + } + + /** + * Retourne le libelle du statut d'une charge (impaye, payee) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long + * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) + * @return string Label + */ + function getLibStatut($mode=0,$alreadypaid=-1) + { + return $this->LibStatut($this->paye,$mode,$alreadypaid); + } + + /** + * Return label for given status + * + * @param int $statut Id statut + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) + * @return string Label + */ + function LibStatut($statut,$mode=0,$alreadypaid=-1) + { + global $langs; + $langs->load('customers'); + $langs->load('bills'); + + if ($mode == 0) + { + if ($statut == 0) return $langs->trans("Unpaid"); + if ($statut == 1) return $langs->trans("Paid"); + } + if ($mode == 1) + { + if ($statut == 0) return $langs->trans("Unpaid"); + if ($statut == 1) return $langs->trans("Paid"); + } + if ($mode == 2) + { + if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid"); + if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted"); + if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid"); + } + if ($mode == 3) + { + if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1'); + if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3'); + if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6'); + } + if ($mode == 4) + { + if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid"); + if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted"); + if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid"); + } + if ($mode == 5) + { + if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1'); + if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3'); + if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6'); + } + + return "Error, mode/status not found"; + } + + + /** + * Return clicable name (with eventually the picto) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $maxlen Label max length + * @return string Chaine with URL + */ + function getNameUrl($withpicto=0,$maxlen=0) + { + global $langs; + + $result=''; + + if (empty($this->ref)) $this->ref=$this->lib; + + $lien = ''; + $lienfin=''; + + if ($withpicto) $result.=($lien.img_object($langs->trans("ShowSocialContribution").': '.$this->lib,'bill').$lienfin.' '); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$lienfin; + return $result; + } + + /** + * Return amount of payments already done + * + * @return int Amount of payment already done, <0 if KO + */ + function getSumPayment() + { + $table='payment_loan'; + $field='fk_loan'; + + $sql = 'SELECT sum(amount) as amount'; + $sql.= ' FROM '.MAIN_DB_PREFIX.$table; + $sql.= ' WHERE '.$field.' = '.$this->id; + + dol_syslog(get_class($this)."::getSumPayment", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $amount=0; + + $obj = $this->db->fetch_object($resql); + if ($obj) $amount=$obj->amount?$obj->amount:0; + + $this->db->free($resql); + return $amount; + } + else + { + return -1; + } + } + + /** + * Information on record + * + * @param int $id Id of record + * @return void + */ + function info($id) + { + $sql = "SELECT l.rowid, l.tms as datem, l.datec as datec"; + $sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; + $sql.= " WHERE l.rowid = ".$id; + + dol_syslog(get_class($this)."::info", LOG_DEBUG); + $result=$this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + + $this->id = $obj->rowid; + + if ($obj->fk_user_author) { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->datem); + + } + + $this->db->free($result); + + } + else + { + dol_print_error($this->db); + } + } +} + diff --git a/htdocs/compta/loan/class/paymentloan.class.php b/htdocs/compta/loan/class/paymentloan.class.php new file mode 100644 index 00000000000..972fa762b96 --- /dev/null +++ b/htdocs/compta/loan/class/paymentloan.class.php @@ -0,0 +1,603 @@ + + * Copyright (C) 2004-2007 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/sociales/class/paymentsocialcontribution.class.php + * \ingroup facture + * \brief File of class to manage payment of social contributions + */ + +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; + + +/** \class PaymentSocialContribution + * \brief Class to manage payments of social contributions + */ +class PaymentSocialContribution extends CommonObject +{ + public $element='paiementcharge'; //!< Id that identify managed objects + public $table_element='paiementcharge'; //!< Name of table without prefix where object is stored + + var $id; + var $ref; + + var $fk_charge; + var $datec=''; + var $tms=''; + var $datep=''; + var $amount; // Total amount of payment + var $amounts=array(); // Array of amounts + var $fk_typepaiement; + var $num_paiement; + var $note; + var $fk_bank; + var $fk_user_creat; + var $fk_user_modif; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + $this->db = $db; + } + + /** + * Create payment of social contribution into database. + * Use this->amounts to have list of lines for the payment + * + * @param User $user User making payment + * @return int <0 if KO, id of payment if OK + */ + function create($user) + { + global $conf, $langs; + + $error=0; + + $now=dol_now(); + + // Validate parametres + if (! $this->datepaye) + { + $this->error='ErrorBadValueForParameter'; + return -1; + } + + // Clean parameters + if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge); + if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement); + if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement); + if (isset($this->note)) $this->note=trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + + $totalamount = 0; + foreach ($this->amounts as $key => $value) // How payment is dispatch + { + $newvalue = price2num($value,'MT'); + $this->amounts[$key] = $newvalue; + $totalamount += $newvalue; + } + $totalamount = price2num($totalamount); + + // Check parameters + if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null + + + $this->db->begin(); + + if ($totalamount != 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount,"; + $sql.= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)"; + $sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',"; + $sql.= " '".$this->db->idate($this->datepaye)."',"; + $sql.= " ".$totalamount.","; + $sql.= " ".$this->paiementtype.", '".$this->db->escape($this->num_paiement)."', '".$this->db->escape($this->note)."', ".$user->id.","; + $sql.= " 0)"; + + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge"); + } + else + { + $error++; + } + + } + + if ($totalamount != 0 && ! $error) + { + $this->amount=$totalamount; + $this->total=$totalamount; // deprecated + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + } + + /** + * Load object in memory from database + * + * @param int $id Id object + * @return int <0 if KO, >0 if OK + */ + function fetch($id) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + $sql.= " t.fk_charge,"; + $sql.= " t.datec,"; + $sql.= " t.tms,"; + $sql.= " t.datep,"; + $sql.= " t.amount,"; + $sql.= " t.fk_typepaiement,"; + $sql.= " t.num_paiement,"; + $sql.= " t.note,"; + $sql.= " t.fk_bank,"; + $sql.= " t.fk_user_creat,"; + $sql.= " t.fk_user_modif,"; + $sql.= " pt.code as type_code, pt.libelle as type_libelle,"; + $sql.= ' b.fk_account'; + $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."paiementcharge as t)"; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; + $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepaiement = pt.id"; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + + $this->fk_charge = $obj->fk_charge; + $this->datec = $this->db->jdate($obj->datec); + $this->tms = $this->db->jdate($obj->tms); + $this->datep = $this->db->jdate($obj->datep); + $this->amount = $obj->amount; + $this->fk_typepaiement = $obj->fk_typepaiement; + $this->num_paiement = $obj->num_paiement; + $this->note = $obj->note; + $this->fk_bank = $obj->fk_bank; + $this->fk_user_creat = $obj->fk_user_creat; + $this->fk_user_modif = $obj->fk_user_modif; + + $this->type_code = $obj->type_code; + $this->type_libelle = $obj->type_libelle; + + $this->bank_account = $obj->fk_account; + $this->bank_line = $obj->fk_bank; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + return -1; + } + } + + + /** + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function update($user=0, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + + if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge); + if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement); + if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement); + if (isset($this->note)) $this->note=trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + + + + // Check parameters + // Put here code to add control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET"; + + $sql.= " fk_charge=".(isset($this->fk_charge)?$this->fk_charge:"null").","; + $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; + $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; + $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; + $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; + $sql.= " fk_typepaiement=".(isset($this->fk_typepaiement)?$this->fk_typepaiement:"null").","; + $sql.= " num_paiement=".(isset($this->num_paiement)?"'".$this->db->escape($this->num_paiement)."'":"null").","; + $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").","; + $sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").","; + $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").","; + $sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null").""; + + + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * Delete object in database + * + * @param User $user User that delete + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + $this->db->begin(); + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; + $sql.= " WHERE type='payment_sc' AND url_id=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge"; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + + /** + * Load an object from its id and create a new one in database + * + * @param int $fromid Id of object to clone + * @return int New id of clone + */ + function createFromClone($fromid) + { + global $user,$langs; + + $error=0; + + $object=new PaymentSocialContribution($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + $object->id=0; + $object->statut=0; + + // Clear fields + // ... + + // Create clone + $result=$object->create($user); + + // Other options + if ($result < 0) + { + $this->error=$object->error; + $error++; + } + + if (! $error) + { + + + + } + + // End + if (! $error) + { + $this->db->commit(); + return $object->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + function initAsSpecimen() + { + $this->id=0; + + $this->fk_charge=''; + $this->datec=''; + $this->tms=''; + $this->datep=''; + $this->amount=''; + $this->fk_typepaiement=''; + $this->num_paiement=''; + $this->note=''; + $this->fk_bank=''; + $this->fk_user_creat=''; + $this->fk_user_modif=''; + + + } + + + /** + * Add record into bank for payment with links between this bank record and invoices of payment. + * All payment properties must have been set first like after a call to create(). + * + * @param User $user Object of user making payment + * @param string $mode 'payment_sc' + * @param string $label Label to use in bank record + * @param int $accountid Id of bank account to do link with + * @param string $emetteur_nom Name of transmitter + * @param string $emetteur_banque Name of bank + * @return int <0 if KO, >0 if OK + */ + function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque) + { + global $conf; + + $error=0; + + if (! empty($conf->banque->enabled)) + { + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + + $acc = new Account($this->db); + $acc->fetch($accountid); + + $total=$this->total; + if ($mode == 'payment_sc') $total=-$total; + + // Insert payment into llx_bank + $bank_line_id = $acc->addline( + $this->datepaye, + $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example") + $label, + $total, + $this->num_paiement, + '', + $user, + $emetteur_nom, + $emetteur_banque + ); + + // Mise a jour fk_bank dans llx_paiement. + // On connait ainsi le paiement qui a genere l'ecriture bancaire + if ($bank_line_id > 0) + { + $result=$this->update_fk_bank($bank_line_id); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + + // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction + $url=''; + if ($mode == 'payment_sc') $url=DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='; + if ($url) + { + $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + } + + // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) + $linkaddedforthirdparty=array(); + foreach ($this->amounts as $key => $value) + { + if ($mode == 'payment_sc') + { + $socialcontrib = new ChargeSociales($this->db); + $socialcontrib->fetch($key); + $result=$acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc'); + if ($result <= 0) dol_print_error($this->db); + } + } + } + else + { + $this->error=$acc->error; + $error++; + } + } + + if (! $error) + { + return 1; + } + else + { + return -1; + } + } + + + /** + * Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee + * + * @param int $id_bank Id if bank + * @return int >0 if OK, <=0 if KO + */ + function update_fk_bank($id_bank) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + $this->error=$this->db->error(); + return 0; + } + } + + /** + * Renvoie nom clicable (avec eventuellement le picto) + * + * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul + * @param int $maxlen Longueur max libelle + * @return string Chaine avec URL + */ + function getNomUrl($withpicto=0,$maxlen=0) + { + global $langs; + + $result=''; + + if (empty($this->ref)) $this->ref=$this->lib; + + if (!empty($this->id)) + { + $lien = ''; + $lienfin=''; + + if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$lienfin.' '); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$lienfin; + } + + return $result; + } +} + + diff --git a/htdocs/compta/loan/document.php b/htdocs/compta/loan/document.php new file mode 100644 index 00000000000..ad5af8f84c2 --- /dev/null +++ b/htdocs/compta/loan/document.php @@ -0,0 +1,178 @@ + + * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005 Simon TOSSER + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2013 Cédric Salvador + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/sociales/document.php + * \ingroup tax + * \brief Page with attached files on social contributions + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; + +$langs->load("other"); +$langs->load("companies"); +$langs->load("compta"); +$langs->load("bills"); + +$id = GETPOST('id','int'); +$action = GETPOST("action"); +$confirm = GETPOST('confirm', 'alpha'); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); + + +// Get parameters +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if ($page == -1) { + $page = 0; +} +$offset = $conf->liste_limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (! $sortorder) $sortorder="ASC"; +if (! $sortfield) $sortfield="name"; + + +$object = new ChargeSociales($db); +if ($id > 0) $object->fetch($id); + +$upload_dir = $conf->tax->dir_output.'/'.dol_sanitizeFileName($object->ref); +$modulepart='tax'; + + +/* + * Actions + */ + +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; + + +/* + * View + */ + +$form = new Form($db); + +$help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; +llxHeader("",$langs->trans("SocialContribution"),$help_url); + +if ($object->id) +{ + $alreadypayed=$object->getSommePaiement(); + + $head=tax_prepare_head($object, $user); + + dol_fiche_head($head, 'documents', $langs->trans("SocialContribution"), 0, 'bill'); + + + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + + + print ''; + + // Ref + print '"; + + // Label + if ($action == 'edit') + { + print ''; + } + else + { + print ''; + } + + // Type + print ""; + + // Period end date + print ""; + print ""; + print ""; + + // Due date + if ($action == 'edit') + { + print '"; + } + else { + print ""; + } + + // Amount + print ''; + + // Status + print ''; + + print ''; + print ''; + print '
'.$langs->trans("Ref").''; + print $form->showrefnav($object,'id'); + print "
'.$langs->trans("Label").''; + print ''; + print '
'.$langs->trans("Label").''.$object->lib.'
".$langs->trans("Type")."".$object->type_libelle."
".$langs->trans("PeriodEndDate").""; + if ($action == 'edit') + { + print $form->select_date($object->periode, 'period', 0, 0, 0, 'charge', 1); + } + else + { + print dol_print_date($object->periode,"day"); + } + print "
'.$langs->trans("DateDue").""; + print $form->select_date($object->date_ech, 'ech', 0, 0, 0, 'charge', 1); + print "
".$langs->trans("DateDue")."".dol_print_date($object->date_ech,'day')."
'.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Status").''.$object->getLibStatut(4,$alreadypayed).'
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
'; + + print '
'; + + $modulepart = 'tax'; + $permission = $user->rights->tax->charges->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; +} +else +{ + print $langs->trans("ErrorUnknown"); +} + + +llxFooter(); + +$db->close(); diff --git a/htdocs/compta/loan/index.html b/htdocs/compta/loan/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/compta/loan/index.php b/htdocs/compta/loan/index.php new file mode 100644 index 00000000000..d84d1897c24 --- /dev/null +++ b/htdocs/compta/loan/index.php @@ -0,0 +1,208 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/loan/index.php + * \ingroup loan + * \brief Page to list all loans + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; + +$langs->load("loan"); +$langs->load("compta"); +$langs->load("banks"); +$langs->load("bills"); + +// Security check +$socid = isset($_GET["socid"])?$_GET["socid"]:''; +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'loan', '', '', ''); + +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if ($page == -1) { $page = 0; } +$offset = $conf->liste_limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +$limit = $conf->liste_limit; +if (! $sortfield) $sortfield="l.rowid"; +if (! $sortorder) $sortorder="DESC"; + +$year=$_GET["year"]; +$filtre=$_GET["filtre"]; + +/* + * View + */ + +$form = new Form($db); +$loan = new Loan($db); + +llxHeader(); + +$sql = "SELECT cs.rowid as id, cs.fk_type as type, "; +$sql.= " cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode,"; +$sql.= " c.libelle as type_lib,"; +$sql.= " SUM(pc.amount) as alreadypayed"; +$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,"; +$sql.= " ".MAIN_DB_PREFIX."chargesociales as cs"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid"; +$sql.= " WHERE cs.fk_type = c.id"; +$sql.= " AND cs.entity = ".$conf->entity; +if (GETPOST("search_label")) $sql.=" AND cs.libelle LIKE '%".$db->escape(GETPOST("search_label"))."%'"; +if ($year > 0) +{ + $sql .= " AND ("; + // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance, + // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire + $sql .= " (cs.periode IS NOT NULL AND date_format(cs.periode, '%Y') = '".$year."') "; + $sql .= "OR (cs.periode IS NULL AND date_format(cs.date_ech, '%Y') = '".$year."')"; + $sql .= ")"; +} +if ($filtre) { + $filtre=str_replace(":","=",$filtre); + $sql .= " AND ".$filtre; +} +if ($typeid) { + $sql .= " AND cs.fk_type=".$typeid; +} +$sql.= " GROUP BY cs.rowid, cs.fk_type, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, c.libelle"; +$sql.= $db->order($sortfield,$sortorder); +$sql.= $db->plimit($limit+1,$offset); + + +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + $i = 0; + $var=true; + + $param=''; + if ($year) $param.='&year='.$year; + if ($typeid) $param.='&typeid='.$typeid; + + if ($year) + { + print_fiche_titre($langs->trans("SocialContributions"),($year?"".img_previous()." ".$langs->trans("Year")." $year ".img_next()."":"")); + } + else + { + print_barre_liste($langs->trans("SocialContributions"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$totalnboflines); + } + + if (empty($mysoc->country_id) && empty($mysoc->country_code)) + { + print '
'; + $langs->load("errors"); + $countrynotdefined=$langs->trans("ErrorSetACountryFirst"); + print $countrynotdefined; + print '
'; + } + else + { + + print ''; + + print ""; + + print ""; + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"id","",$param,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"cs.libelle","",$param,'align="left"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("PeriodEndDate"),$_SERVER["PHP_SELF"],"periode","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"cs.amount","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DateDue"),$_SERVER["PHP_SELF"],"cs.date_ech","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cs.paye","",$param,'align="right"',$sortfield,$sortorder); + print "\n"; + + print ''; + print ''; + print ''; + // Type + print ''; + // Period end date + print ''; + print ''; + print ''; + print ''; + print "\n"; + + while ($i < min($num,$limit)) + { + $obj = $db->fetch_object($resql); + + $var = !$var; + print ""; + + // Ref + print ''; + + // Label + print ''; + + // Type + print ''; + + // Date end period + print ''; + + print ''; + + // Due date + print ''; + + print ''; + + print ''; + $i++; + } + + print '
 '; + $formsocialcontrib->select_type_socialcontrib($typeid,'typeid',1,16,0); + print '   '; + print ''; + print '
'; + $loan->id=$obj->id; + $loan->lib=$obj->id; + $loan->ref=$obj->id; + print $loan->getNomUrl(1,'20'); + print ''.dol_trunc($obj->libelle,42).''.dol_trunc($obj->type_lib,16).''; + if ($obj->periode) + { + print 'jdate($obj->periode)).'">'.dol_print_date($db->jdate($obj->periode),'day').''; + } + else + { + print ' '; + } + print ''.price($obj->amount).''.dol_print_date($db->jdate($obj->date_ech), 'day').''.$loan->LibStatut($obj->paye,5,$obj->alreadypayed).'
'; + + print ''; + } +} +else +{ + dol_print_error($db); +} + +$db->close(); + +llxFooter(); diff --git a/htdocs/compta/loan/info.php b/htdocs/compta/loan/info.php new file mode 100644 index 00000000000..c41787b7d08 --- /dev/null +++ b/htdocs/compta/loan/info.php @@ -0,0 +1,65 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/sociales/info.php + * \ingroup tax + * \brief Page with info about social contribution + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + +$langs->load("compta"); +$langs->load("bills"); + +$id=GETPOST('id','int'); +$action=GETPOST("action"); + +// Security check +$socid = GETPOST('socid','int'); +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); + + +/* + * View + */ + +$help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; +llxHeader("",$langs->trans("SocialContribution"),$help_url); + +$chargesociales = new ChargeSociales($db); +$chargesociales->fetch($id); +$chargesociales->info($id); + +$head = tax_prepare_head($chargesociales); + +dol_fiche_head($head, 'info', $langs->trans("SocialContribution"), 0, 'bill'); + + +print '
'; +dol_print_object_info($chargesociales); +print '
'; + +print ''; + +llxFooter(); + +$db->close(); diff --git a/htdocs/core/lib/loan.lib.php b/htdocs/core/lib/loan.lib.php new file mode 100644 index 00000000000..58ebaef7bfd --- /dev/null +++ b/htdocs/core/lib/loan.lib.php @@ -0,0 +1,66 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/lib/loan.lib.php + * \ingroup loan + * \brief Library for loan module + */ + + +/** + * Prepare array with list of tabs + * + * @param Object $object Object related to tabs + * @return array Array of tabs to show + */ +function loan_prepare_head($object) +{ + global $langs, $conf; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/compta/loan/card.php?id='.$object->id; + $head[$h][1] = $langs->trans('Card'); + $head[$h][2] = 'card'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'loan'); + + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $upload_dir = $conf->loan->dir_output . "/" . dol_sanitizeFileName($object->ref); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); + $head[$h][0] = DOL_URL_ROOT.'/compta/loan/document.php?id='.$object->id; + $head[$h][1] = $langs->trans("Documents"); + if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; + $head[$h][2] = 'documents'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/compta/loan/info.php?id='.$object->id; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; + + complete_head_from_modules($conf,$langs,$object,$head,$h,'loan','remove'); + + return $head; +} \ No newline at end of file diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 1d7aa1a5a9a..fd37ccacaf9 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -134,9 +134,9 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0) } // Financial - $tmpentry=array('enabled'=>(! empty($conf->comptabilite->enabled) || ! empty($conf->accounting->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->don->enabled) || ! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled)), - 'perms'=>(! empty($user->rights->compta->resultat->lire) || ! empty($user->rights->accounting->plancompte->lire) || ! empty($user->rights->facture->lire) || ! empty($user->rights->don->lire) || ! empty($user->rights->tax->charges->lire) || ! empty($user->rights->salaries->read)), - 'module'=>'comptabilite|accounting|facture|don|tax|salaries'); + $tmpentry=array('enabled'=>(! empty($conf->comptabilite->enabled) || ! empty($conf->accounting->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->don->enabled) || ! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled) || ! empty($conf->loan->enabled)), + 'perms'=>(! empty($user->rights->compta->resultat->lire) || ! empty($user->rights->accounting->plancompte->lire) || ! empty($user->rights->facture->lire) || ! empty($user->rights->don->lire) || ! empty($user->rights->tax->charges->lire) || ! empty($user->rights->salaries->read) || ! empty($user->rights->loan->read)), + 'module'=>'comptabilite|accounting|facture|don|tax|salaries|loan'); $showmode=dol_eldy_showmenu($type_user, $tmpentry, $listofmodulesforexternal); if ($showmode) { @@ -802,11 +802,11 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu } // Taxes and social contributions - if (! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled)) + if (! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled) || ! empty($conf->loan->enabled)) { global $mysoc; - $permtoshowmenu=((! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) || (! empty($conf->salaries->enabled) && $user->rights->salaries->read)); + $permtoshowmenu=((! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) || (! empty($conf->salaries->enabled) && $user->rights->salaries->read) || (! empty($conf->loan->enabled) && $user->rights->loan->read)); $newmenu->add("/compta/charges/index.php?leftmenu=tax&mainmenu=accountancy",$langs->trans("MenuSpecialExpenses"), 0, $permtoshowmenu, '', $mainmenu, 'tax'); // Salaries @@ -817,6 +817,15 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if (empty($leftmenu) || preg_match('/^tax_salary/i',$leftmenu)) $newmenu->add("/compta/salaries/fiche.php?leftmenu=tax_salary&action=create",$langs->trans("NewPayment"),2,$user->rights->salaries->write); if (empty($leftmenu) || preg_match('/^tax_salary/i',$leftmenu)) $newmenu->add("/compta/salaries/index.php?leftmenu=tax_salary",$langs->trans("Payments"),2,$user->rights->salaries->read); } + + // Loan + if (! empty($conf->loan->enabled)) + { + $langs->load("loan"); + $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy",$langs->trans("Loans"),1,$user->rights->loan->read, '', $mainmenu, 'tax_loan'); + if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/card.php?leftmenu=tax_loan&action=create",$langs->trans("NewLoan"),2,$user->rights->loan->write); + if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read); + } // Social contributions if (! empty($conf->tax->enabled)) diff --git a/htdocs/core/modules/modLoan.class.php b/htdocs/core/modules/modLoan.class.php new file mode 100644 index 00000000000..fb2de1e3a02 --- /dev/null +++ b/htdocs/core/modules/modLoan.class.php @@ -0,0 +1,173 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + +/** + * \defgroup tax Module Loans + * \brief Module to include loans management + * \file htdocs/core/modules/modLoan.class.php + * \ingroup loan + * \brief File to activate module loan + */ +include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; + + +/** + * Class to manage loan module + */ +class modLoan extends DolibarrModules +{ + + /** + * Constructor. Define names, constants, directories, boxes, permissions + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + global $conf; + + $this->db = $db; + $this->numero = 520; + + $this->family = "financial"; + // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) + $this->name = preg_replace('/^mod/i','',get_class($this)); + // Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) + $this->description = "Loans management"; + + // Possible values for version are: 'development', 'experimental', 'dolibarr' or version + $this->version = 'development'; + + $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); + $this->special = 0; + $this->picto='bill'; + + // Data directories to create when module is enabled + $this->dirs = array("/loan/temp"); + + // Config pages + $this->config_page_url = array('loan.php'); + + // Dependances + $this->depends = array(); + $this->requiredby = array(); + $this->conflictwith = array(); + $this->langfiles = array("loan"); + + // Constants + $this->const = array(); + $this->const[0] = array( + "LOAN_ACCOUNTING_ACCOUNT_CAPITAL", + "chaine", + "164" + ); + $this->const[1] = array( + "LOAN_ACCOUNTING_ACCOUNT_INTEREST", + "chaine", + "6611" + ); + $this->const[1] = array( + "LOAN_ACCOUNTING_ACCOUNT_INSURANCE", + "chaine", + "6162" + ); + + // Boxes + $this->boxes = array(); + + // Permissions + $this->rights = array(); + $this->rights_class = 'loan'; + $r=0; + + $r++; + $this->rights[$r][0] = 520; + $this->rights[$r][1] = 'Read loans'; + $this->rights[$r][2] = 'r'; + $this->rights[$r][3] = 1; + $this->rights[$r][4] = 'read'; + $this->rights[$r][5] = ''; + + $r++; + $this->rights[$r][0] = 522; + $this->rights[$r][1] = 'Create/modify loans'; + $this->rights[$r][2] = 'w'; + $this->rights[$r][3] = 0; + $this->rights[$r][4] = 'write'; + $this->rights[$r][5] = ''; + + $r++; + $this->rights[$r][0] = 524; + $this->rights[$r][1] = 'Delete loans'; + $this->rights[$r][2] = 'd'; + $this->rights[$r][3] = 0; + $this->rights[$r][4] = 'delete'; + $this->rights[$r][5] = ''; + + $r++; + $this->rights[$r][0] = 527; + $this->rights[$r][1] = 'Export loans'; + $this->rights[$r][2] = 'r'; + $this->rights[$r][3] = 0; + $this->rights[$r][4] = 'export'; + $this->rights[$r][5] = ''; + + + // Exports + //-------- + $r=0; + + } + + + /** + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories + * + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + function init($options='') + { + global $conf; + + // Clean before activation + $this->remove($options); + + $sql = array(); + + return $this->_init($sql,$options); + } + + /** + * Function called when module is disabled. + * Remove from database constants, boxes and permissions from Dolibarr database. + * Data directories are not deleted + * + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + function remove($options='') + { + $sql = array(); + + return $this->_remove($sql,$options); + } + +} diff --git a/htdocs/install/mysql/tables/llx_loan.sql b/htdocs/install/mysql/tables/llx_loan.sql new file mode 100644 index 00000000000..2ca026ba417 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_loan.sql @@ -0,0 +1,47 @@ +-- ======================================================================== +-- Copyright (C) 2014 Alexandre Spangaro +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ======================================================================== + +create table llx_loan +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, + datec datetime, + tms timestamp, + + label varchar(80) NOT NULL, + fk_bank integer, + + capital real default 0 NOT NULL, + datestart date, + dateend date, + nbterm real, + rate double NOT NULL, + + note text, + + capital_position real default 0, -- If not a new loan, just have the position of capital + date_position date, + + accountancy_account_capital varchar(32), + accountancy_account_insurance varchar(32), + accountancy_account_interest varchar(32), + + fk_user_author integer DEFAULT NULL, + fk_user_modif integer DEFAULT NULL, + active tinyint DEFAULT 1 NOT NULL +)ENGINE=innodb; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_payment_loan.sql b/htdocs/install/mysql/tables/llx_payment_loan.sql new file mode 100644 index 00000000000..83bb3ac2548 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_payment_loan.sql @@ -0,0 +1,33 @@ +-- =================================================================== +-- Copyright (C) 2014 Alexandre Spangaro +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + +create table llx_payment_loan +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_loan integer, + datec datetime, -- creation date + tms timestamp, + datep datetime, -- payment date + amount real DEFAULT 0, + fk_typepayment integer NOT NULL, + num_payment varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, -- creation user + fk_user_modif integer -- last modification user +)ENGINE=innodb; From 1409c8f4503c7f527f7faf538d7031bbbfdc6adc Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 21 Sep 2014 21:38:33 +0200 Subject: [PATCH 02/24] Continue to work --- htdocs/compta/loan/card.php | 40 +++++++++++++++---------- htdocs/compta/loan/class/loan.class.php | 22 +++++++------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/htdocs/compta/loan/card.php b/htdocs/compta/loan/card.php index f8cf4d29327..3e7ce94520a 100644 --- a/htdocs/compta/loan/card.php +++ b/htdocs/compta/loan/card.php @@ -24,6 +24,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $langs->load("compta"); $langs->load("bills"); @@ -71,16 +72,16 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // Add loan if ($action == 'add' && $user->rights->loan->write) { - $dateech=@dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]); - $dateperiod=@dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]); - if (! $dateech) + $datestart=dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); + $dateend=dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); + if (! $datestart) { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors'); + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); $action = 'create'; } - elseif (! $dateperiod) + elseif (! $dateend) { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors'); + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors'); $action = 'create'; } elseif (! $_POST["capital"]) @@ -92,10 +93,17 @@ if ($action == 'add' && $user->rights->loan->write) { $loan = new Loan($db); - $loan->label = $_POST["label"]; - $loan->date_ech = $dateech; - $loan->periode = $dateperiod; - $loan->capital = $_POST["capital"]; + $loan->label = GETPOST("label"); + $loan->fk_bank = GETPOST("accountid"); + $loan->capital = GETPOST("capital"); + $loan->datestart = $datestart; + $loan->dateend = $dateend; + $loan->nbterm = GETPOST("nbterm"); + $loan->rate = GETPOST("rate"); + + $loan->account_capital = GETPOST("accountancy_account_capital"); + $loan->account_insurance = GETPOST("accountancy_account_insurance"); + $loan->account_interest = GETPOST("accountancy_account_interest"); $id=$loan->create($user); if ($id <= 0) @@ -125,9 +133,9 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->loan->write) $loan = new Loan($db); $result=$loan->fetch($_GET["id"]); - $loan->lib=$_POST["label"]; - $loan->date_ech=$dateech; - $loan->periode=$dateperiod; + $loan->label=$_POST["label"]; + $loan->datestart=$datestart; + $loan->dateend=$dateend; $result=$loan->update($user); if ($result <= 0) @@ -188,13 +196,13 @@ if ($action == 'create') // Date Start print ""; print ''.$langs->trans("DateStart").''; - print $form->select_date($datestart?$datestart:-1,'','','','','add',1,1); + print $form->select_date($datestart?$datestart:-1,'start','','','','add',1,1); print ''; // Date End print ""; print ''.$langs->trans("DateEnd").''; - print $form->select_date($dateend?$dateend:-1,'','','','','add',1,1); + print $form->select_date($dateend?$dateend:-1,'end','','','','add',1,1); print ''; // Number of terms @@ -430,7 +438,7 @@ if ($id > 0) // Edit if ($user->rights->loan->write) { - print "id&action=edit\">".$langs->trans("Modify").""; + print "id&action=edit\">".$langs->trans("Modify").""; } // Emettre paiement diff --git a/htdocs/compta/loan/class/loan.class.php b/htdocs/compta/loan/class/loan.class.php index 74aed1d048b..8b6bba2abf5 100644 --- a/htdocs/compta/loan/class/loan.class.php +++ b/htdocs/compta/loan/class/loan.class.php @@ -34,7 +34,7 @@ class Loan extends CommonObject var $id; var $ref; - var $date_start; + var $datestart; var $dateend; var $label; var $capital; @@ -116,8 +116,8 @@ class Loan extends CommonObject // clean parameters $newcapital=price2num($this->capital,'MT'); - // Validation parametres - if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode)) + // Check parameters + if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend)) { $this->error="ErrorBadParameter"; return -2; @@ -125,10 +125,10 @@ class Loan extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount, entity)"; - $sql.= " VALUES (".$this->type.",'".$this->db->escape($this->lib)."',"; - $sql.= " '".$this->db->idate($this->date_ech)."','".$this->db->idate($this->periode)."',"; - $sql.= " '".price2num($newamount)."',"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, date_ech, periode, amount, entity)"; + $sql.= " VALUES ('".$this->db->escape($this->label)."',"; + $sql.= " '".$this->db->idate($this->datestart)."','".$this->db->idate($this->dateend)."',"; + $sql.= " '".price2num($newcapital)."',"; $sql.= " ".$conf->entity; $sql.= ")"; @@ -136,9 +136,9 @@ class Loan extends CommonObject $resql=$this->db->query($sql); if ($resql) { - $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales"); + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."loan"); - //dol_syslog("ChargesSociales::create this->id=".$this->id); + //dol_syslog("Loans::create this->id=".$this->id); $this->db->commit(); return $this->id; } @@ -152,7 +152,7 @@ class Loan extends CommonObject /** - * Delete a social contribution + * Delete a loan * * @param User $user Object user making delete * @return int <0 if KO, >0 if OK @@ -223,7 +223,7 @@ class Loan extends CommonObject /** - * Met a jour une charge sociale + * Update loan * * @param User $user Utilisateur qui modifie * @return int <0 si erreur, >0 si ok From f51df9da705e6f42230f03e4f787f3d836b951f1 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 22 Sep 2014 08:24:58 +0200 Subject: [PATCH 03/24] Add loan language file --- .tx/config | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.tx/config b/.tx/config index a89b56c1013..bf62f32d9d6 100644 --- a/.tx/config +++ b/.tx/config @@ -176,6 +176,12 @@ source_file = htdocs/langs/en_US/link.lang source_lang = en_US type = MOZILLAPROPERTIES +[dolibarr.loan] +file_filter = htdocs/langs//loan.lang +source_file = htdocs/langs/en_US/loan.lang +source_lang = en_US +type = MOZILLAPROPERTIES + [dolibarr.mailmanspip] file_filter = htdocs/langs//mailmanspip.lang source_file = htdocs/langs/en_US/mailmanspip.lang From c53663c8858801ba1002a2be7a27c9127e2b2366 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 22 Sep 2014 08:25:39 +0200 Subject: [PATCH 04/24] Continue to work --- htdocs/compta/loan/card.php | 174 +++++++++--------- htdocs/compta/loan/class/loan.class.php | 54 +++++- .../compta/loan/class/paymentloan.class.php | 6 +- htdocs/compta/loan/document.php | 77 ++++---- htdocs/compta/loan/info.php | 31 ++-- 5 files changed, 189 insertions(+), 153 deletions(-) diff --git a/htdocs/compta/loan/card.php b/htdocs/compta/loan/card.php index 3e7ce94520a..6b075e3d758 100644 --- a/htdocs/compta/loan/card.php +++ b/htdocs/compta/loan/card.php @@ -153,7 +153,7 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->loan->write) $form = new Form($db); -$help_url='EN:Module_Loan|FR:Module Emprunt'; +$help_url='EN:Module_Loan|FR:Module_Emprunt'; llxHeader("",$langs->trans("Loan"),$help_url); @@ -268,7 +268,7 @@ if ($action == 'create') if ($id > 0) { $object = new Loan($db); - $result=$object->fetch($id); + $result = $object->fetch($id); if ($result > 0) { @@ -313,101 +313,41 @@ if ($id > 0) { print ''.$langs->trans("Label").''.$object->label.''; } + + // Capital + print ''.$langs->trans("Capital").''.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).''; - $rowspan=5; - print ''; - - /* - * Payments - */ - $sql = "SELECT p.rowid, p.num_payment, datep as dp, p.amount,"; - $sql.= "c.libelle as paiement_type"; - $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; - $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; - $sql.= ", ".MAIN_DB_PREFIX."loan as l"; - $sql.= " WHERE p.fk_loan = ".$id; - $sql.= " AND p.fk_loan = l.rowid"; - $sql.= " AND l.entity = ".$conf->entity; - $sql.= " AND p.fk_typepayment = c.id"; - $sql.= " ORDER BY dp DESC"; - - //print $sql; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; $total = 0; - echo ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; - print "'; - print '\n"; - print "\n"; - print '\n"; - print ""; - $totalpaye += $objp->amount; - $i++; - } - - if ($object->paye == 0) - { - print "\n"; - print "\n"; - - $resteapayer = $object->amount - $totalpaye; - - print ""; - print "\n"; - } - print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; - print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$objp->paiement_type.' '.$objp->num_paiement."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaye)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("RemainderToPay")." :".price($resteapayer)." ".$langs->trans("Currency".$conf->currency)."
"; - $db->free($resql); - } - else - { - dol_print_error($db); - } - print ""; - - print ""; - - // Period end date - print "".$langs->trans("PeriodEndDate").""; + // Date start + print "".$langs->trans("DateStart").""; print ""; if ($action == 'edit') { - print $form->select_date($object->periode, 'period', 0, 0, 0, 'charge', 1); + print $form->select_date($object->datestart, 'start', 0, 0, 0, 'update', 1); } else { - print dol_print_date($object->periode,"day"); + print dol_print_date($object->datestart,"day"); } print ""; - // Due date + // Date end + print "".$langs->trans("DateEnd").""; + print ""; if ($action == 'edit') { - print ''.$langs->trans("DateDue").""; - print $form->select_date($object->date_ech, 'ech', 0, 0, 0, 'charge', 1); - print ""; + print $form->select_date($object->dateend, 'end', 0, 0, 0, 'update', 1); } - else { - print "".$langs->trans("DateDue")."".dol_print_date($object->date_ech,'day').""; + else + { + print dol_print_date($object->dateend,"day"); } - - // Amount - print ''.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).''; + print ""; + + // Nbterms + print ''.$langs->trans("Nbterms").''.$object->nbterm.''; + + // Rate + print ''.$langs->trans("Rate").''.$object->rate.''; // Status print ''.$langs->trans("Status").''.$object->getLibStatut(4, $totalpaye).''; @@ -461,6 +401,74 @@ if ($id > 0) print ""; } + + print '
'; + print ''; + print '"; + print "
'; + + /* + * Payments + */ + $sql = "SELECT p.rowid, p.num_payment, datep as dp, p.amount,"; + $sql.= "c.libelle as paiement_type"; + $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; + $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; + $sql.= ", ".MAIN_DB_PREFIX."loan as l"; + $sql.= " WHERE p.fk_loan = ".$id; + $sql.= " AND p.fk_loan = l.rowid"; + $sql.= " AND l.entity = ".$conf->entity; + $sql.= " AND p.fk_typepayment = c.id"; + $sql.= " ORDER BY dp DESC"; + + //print $sql; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; $total = 0; + echo ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + print "'; + print '\n"; + print "\n"; + print '\n"; + print ""; + $totalpaye += $objp->amount; + $i++; + } + + if ($object->paye == 0) + { + print "\n"; + print "\n"; + + $resteapayer = $object->amount - $totalpaye; + + print ""; + print "\n"; + } + print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; + print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$objp->paiement_type.' '.$objp->num_paiement."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaye)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("RemainderToPay")." :".price($resteapayer)." ".$langs->trans("Currency".$conf->currency)."
"; + $db->free($resql); + } + else + { + dol_print_error($db); + } + print "
"; } else { diff --git a/htdocs/compta/loan/class/loan.class.php b/htdocs/compta/loan/class/loan.class.php index 8b6bba2abf5..b63f9b32eff 100644 --- a/htdocs/compta/loan/class/loan.class.php +++ b/htdocs/compta/loan/class/loan.class.php @@ -47,6 +47,9 @@ class Loan extends CommonObject var $date_creation; var $date_modification; var $date_validation; + var $fk_bank; + var $fk_user_creat; + var $fk_user_modif; /** @@ -68,8 +71,7 @@ class Loan extends CommonObject */ function fetch($id) { - $sql = "SELECT l.rowid, l.datestart,"; - $sql.= " l.label, l.capital"; + $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note"; $sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; $sql.= " WHERE l.rowid = ".$id; @@ -84,8 +86,12 @@ class Loan extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->rowid; $this->datestart = $this->db->jdate($obj->datestart); + $this->dateend = $this->db->jdate($obj->dateend); $this->label = $obj->label; $this->capital = $obj->capital; + $this->nbterm = $obj->nbterm; + $this->rate = $obj->rate; + $this->note = $obj->note; return 1; } @@ -112,9 +118,20 @@ class Loan extends CommonObject function create($user) { global $conf; + + $error=0; + + $now=dol_now(); // clean parameters $newcapital=price2num($this->capital,'MT'); + if (isset($this->note)) $this->note = trim($this->note); + if (isset($this->account_capital)) $this->account_capital = trim($this->account_capital); + if (isset($this->account_insurance)) $this->account_insurance = trim($this->account_insurance); + if (isset($this->account_interest)) $this->account_interest = trim($this->account_interest); + if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); // Check parameters if (! $newcapital > 0 || empty($this->datestart) || empty($this->dateend)) @@ -122,14 +139,31 @@ class Loan extends CommonObject $this->error="ErrorBadParameter"; return -2; } + if (($conf->accounting->enabled) && empty($this->account_capital) && empty($this->account_insurance) && empty($this->account_interest)) + { + $this->error="ErrorAccountingParameter"; + return -2; + } $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, date_ech, periode, amount, entity)"; - $sql.= " VALUES ('".$this->db->escape($this->label)."',"; - $sql.= " '".$this->db->idate($this->datestart)."','".$this->db->idate($this->dateend)."',"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note"; + $sql.= " ,accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity"; + $sql.= " ,datec, fk_user_author)"; + $sql.= " VALUES ('".$this->db->escape($this->label)."',"; + $sql.= " '".$this->db->escape($this->fk_bank)."',"; $sql.= " '".price2num($newcapital)."',"; - $sql.= " ".$conf->entity; + $sql.= " '".$this->db->idate($this->datestart)."',"; + $sql.= " '".$this->db->idate($this->dateend)."',"; + $sql.= " '".$this->db->escape($this->nbterm)."',"; + $sql.= " '".$this->db->escape($this->rate)."',"; + $sql.= " '".$this->db->escape($this->note)."',"; + $sql.= " '".$this->db->escape($this->account_capital)."',"; + $sql.= " '".$this->db->escape($this->account_insurance)."',"; + $sql.= " '".$this->db->escape($this->account_interest)."',"; + $sql.= " ".$conf->entity.","; + $sql.= " '".$this->db->idate($now)."',"; + $sql.= " ".$user->id; $sql.= ")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); @@ -440,7 +474,7 @@ class Loan extends CommonObject */ function info($id) { - $sql = "SELECT l.rowid, l.tms as datem, l.datec as datec"; + $sql = "SELECT l.rowid, l.tms as datem, l.fk_user_author as user_author, l.datec as datec"; $sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; $sql.= " WHERE l.rowid = ".$id; @@ -454,10 +488,10 @@ class Loan extends CommonObject $this->id = $obj->rowid; - if ($obj->fk_user_author) { + if ($obj->user_author) { $cuser = new User($this->db); - $cuser->fetch($obj->fk_user_author); - $this->user_creation = $cuser; + $cuser->fetch($obj->user_author); + $this->user_creation = $cuser; } $this->date_creation = $this->db->jdate($obj->datec); diff --git a/htdocs/compta/loan/class/paymentloan.class.php b/htdocs/compta/loan/class/paymentloan.class.php index 972fa762b96..24d59fb417b 100644 --- a/htdocs/compta/loan/class/paymentloan.class.php +++ b/htdocs/compta/loan/class/paymentloan.class.php @@ -28,10 +28,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; /** \class PaymentSocialContribution * \brief Class to manage payments of social contributions */ -class PaymentSocialContribution extends CommonObject +class PaymentLoan extends CommonObject { - public $element='paiementcharge'; //!< Id that identify managed objects - public $table_element='paiementcharge'; //!< Name of table without prefix where object is stored + public $element='payment_loan'; //!< Id that identify managed objects + public $table_element='payment_loan'; //!< Name of table without prefix where object is stored var $id; var $ref; diff --git a/htdocs/compta/loan/document.php b/htdocs/compta/loan/document.php index ad5af8f84c2..022340270ad 100644 --- a/htdocs/compta/loan/document.php +++ b/htdocs/compta/loan/document.php @@ -1,11 +1,5 @@ - * Copyright (C) 2004-2014 Laurent Destailleur - * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2005 Simon TOSSER - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2013 Cédric Salvador +/* Copyright (C) 2014 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,22 +16,23 @@ */ /** - * \file htdocs/compta/sociales/document.php - * \ingroup tax - * \brief Page with attached files on social contributions + * \file htdocs/compta/loan/document.php + * \ingroup loan + * \brief Page with attached files on loan */ require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; $langs->load("other"); $langs->load("companies"); $langs->load("compta"); $langs->load("bills"); +$langs->load("loan"); $id = GETPOST('id','int'); $action = GETPOST("action"); @@ -45,8 +40,7 @@ $confirm = GETPOST('confirm', 'alpha'); // Security check if ($user->societe_id) $socid=$user->societe_id; -$result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); - +$result = restrictedArea($user, 'loan', $id, '',''); // Get parameters $sortfield = GETPOST("sortfield",'alpha'); @@ -61,12 +55,11 @@ $pagenext = $page + 1; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="name"; - -$object = new ChargeSociales($db); +$object = new Loan($db); if ($id > 0) $object->fetch($id); -$upload_dir = $conf->tax->dir_output.'/'.dol_sanitizeFileName($object->ref); -$modulepart='tax'; +$upload_dir = $conf->loan->dir_output.'/'.dol_sanitizeFileName($object->ref); +$modulepart='loan'; /* @@ -82,16 +75,16 @@ include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php $form = new Form($db); -$help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; -llxHeader("",$langs->trans("SocialContribution"),$help_url); +$help_url='EN:Module_Loan|FR:Module_Emprunt'; +llxHeader("",$langs->trans("Loan"),$help_url); if ($object->id) { - $alreadypayed=$object->getSommePaiement(); + $alreadypayed=$object->getSumPayment(); - $head=tax_prepare_head($object, $user); + $head = loan_prepare_head($object, $user); - dol_fiche_head($head, 'documents', $langs->trans("SocialContribution"), 0, 'bill'); + dol_fiche_head($head, 'documents', $langs->trans("Loan"), 0, 'bill'); // Construit liste des fichiers @@ -114,44 +107,44 @@ if ($object->id) if ($action == 'edit') { print ''.$langs->trans("Label").''; - print ''; + print ''; print ''; } else { - print ''.$langs->trans("Label").''.$object->lib.''; + print ''.$langs->trans("Label").''.$object->label.''; } - // Type - print "".$langs->trans("Type")."".$object->type_libelle.""; + // Amount + print ''.$langs->trans("Capital").''.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).''; - // Period end date - print "".$langs->trans("PeriodEndDate").""; + // Date start + print "".$langs->trans("Datestart").""; print ""; if ($action == 'edit') { - print $form->select_date($object->periode, 'period', 0, 0, 0, 'charge', 1); + print $form->select_date($object->datestart, 'start', 0, 0, 0, 'loan', 1); } else { - print dol_print_date($object->periode,"day"); + print dol_print_date($object->datestart,"day"); } print ""; print ""; - // Due date + // Date end + print "".$langs->trans("Dateend").""; + print ""; if ($action == 'edit') { - print ''.$langs->trans("DateDue").""; - print $form->select_date($object->date_ech, 'ech', 0, 0, 0, 'charge', 1); - print ""; + print $form->select_date($object->dateend, 'end', 0, 0, 0, 'loan', 1); } - else { - print "".$langs->trans("DateDue")."".dol_print_date($object->date_ech,'day').""; + else + { + print dol_print_date($object->dateend,"day"); } - - // Amount - print ''.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).''; + print ""; + print ""; // Status print ''.$langs->trans("Status").''.$object->getLibStatut(4,$alreadypayed).''; @@ -162,8 +155,8 @@ if ($object->id) print ''; - $modulepart = 'tax'; - $permission = $user->rights->tax->charges->creer; + $modulepart = 'loan'; + $permission = $user->rights->loan->write; $param = '&id=' . $object->id; include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } diff --git a/htdocs/compta/loan/info.php b/htdocs/compta/loan/info.php index c41787b7d08..74319ba40b8 100644 --- a/htdocs/compta/loan/info.php +++ b/htdocs/compta/loan/info.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2014 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,18 +16,19 @@ */ /** - * \file htdocs/compta/sociales/info.php - * \ingroup tax - * \brief Page with info about social contribution + * \file htdocs/compta/loan/info.php + * \ingroup loan + * \brief Page with info about loan */ require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $langs->load("compta"); $langs->load("bills"); +$langs->load("loan"); $id=GETPOST('id','int'); $action=GETPOST("action"); @@ -35,27 +36,27 @@ $action=GETPOST("action"); // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; -$result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); +$result = restrictedArea($user, 'loan', $id, '',''); /* * View */ -$help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; -llxHeader("",$langs->trans("SocialContribution"),$help_url); +$help_url='EN:Module_Loan|FR:Module_Emprunt'; +llxHeader("",$langs->trans("Loan"),$help_url); -$chargesociales = new ChargeSociales($db); -$chargesociales->fetch($id); -$chargesociales->info($id); +$loan = new Loan($db); +$loan->fetch($id); +$loan->info($id); -$head = tax_prepare_head($chargesociales); +$head = loan_prepare_head($loan); -dol_fiche_head($head, 'info', $langs->trans("SocialContribution"), 0, 'bill'); +dol_fiche_head($head, 'info', $langs->trans("Loan"), 0, 'bill'); print '
'; -dol_print_object_info($chargesociales); +dol_print_object_info($loan); print '
'; print ''; From 1e15474495ec854b1baa4a62d4a56720cc518800 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Tue, 23 Sep 2014 21:21:38 +0200 Subject: [PATCH 05/24] Continue working --- htdocs/compta/loan/class/loan.class.php | 10 +-- htdocs/compta/loan/index.php | 92 +++++++------------------ 2 files changed, 28 insertions(+), 74 deletions(-) diff --git a/htdocs/compta/loan/class/loan.class.php b/htdocs/compta/loan/class/loan.class.php index b63f9b32eff..afd15ced451 100644 --- a/htdocs/compta/loan/class/loan.class.php +++ b/htdocs/compta/loan/class/loan.class.php @@ -423,14 +423,14 @@ class Loan extends CommonObject $result=''; - if (empty($this->ref)) $this->ref=$this->lib; + if (empty($this->ref)) $this->ref=$this->label; - $lien = ''; - $lienfin=''; + $link = ''; + $linkend=''; - if ($withpicto) $result.=($lien.img_object($langs->trans("ShowSocialContribution").': '.$this->lib,'bill').$lienfin.' '); + if ($withpicto) $result.=($link.img_object($langs->trans("ShowLoan").': '.$this->label,'bill').$linkend.' '); if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$lien.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$lienfin; + if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend; return $result; } diff --git a/htdocs/compta/loan/index.php b/htdocs/compta/loan/index.php index d84d1897c24..41299668dd1 100644 --- a/htdocs/compta/loan/index.php +++ b/htdocs/compta/loan/index.php @@ -45,7 +45,6 @@ $limit = $conf->liste_limit; if (! $sortfield) $sortfield="l.rowid"; if (! $sortorder) $sortorder="DESC"; -$year=$_GET["year"]; $filtre=$_GET["filtre"]; /* @@ -57,33 +56,19 @@ $loan = new Loan($db); llxHeader(); -$sql = "SELECT cs.rowid as id, cs.fk_type as type, "; -$sql.= " cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode,"; -$sql.= " c.libelle as type_lib,"; -$sql.= " SUM(pc.amount) as alreadypayed"; -$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,"; -$sql.= " ".MAIN_DB_PREFIX."chargesociales as cs"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid"; -$sql.= " WHERE cs.fk_type = c.id"; -$sql.= " AND cs.entity = ".$conf->entity; -if (GETPOST("search_label")) $sql.=" AND cs.libelle LIKE '%".$db->escape(GETPOST("search_label"))."%'"; -if ($year > 0) -{ - $sql .= " AND ("; - // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance, - // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire - $sql .= " (cs.periode IS NOT NULL AND date_format(cs.periode, '%Y') = '".$year."') "; - $sql .= "OR (cs.periode IS NULL AND date_format(cs.date_ech, '%Y') = '".$year."')"; - $sql .= ")"; -} +$sql = "SELECT l.rowid as id, l.label, l.capital, l.datestart, l.dateend,"; +$sql.= " SUM(pl.amount) as alreadypayed"; +$sql.= " FROM ".MAIN_DB_PREFIX."loan as l,"; +$sql.= " ".MAIN_DB_PREFIX."payment_loan as pl"; +$sql.= " WHERE pl.fk_loan = l.rowid"; +$sql.= " AND l.entity = ".$conf->entity; +if (GETPOST("search_label")) $sql.=" AND l.label LIKE '%".$db->escape(GETPOST("search_label"))."%'"; + if ($filtre) { $filtre=str_replace(":","=",$filtre); $sql .= " AND ".$filtre; } -if ($typeid) { - $sql .= " AND cs.fk_type=".$typeid; -} -$sql.= " GROUP BY cs.rowid, cs.fk_type, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, c.libelle"; + $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit+1,$offset); @@ -96,18 +81,9 @@ if ($resql) $var=true; $param=''; - if ($year) $param.='&year='.$year; - if ($typeid) $param.='&typeid='.$typeid; - - if ($year) - { - print_fiche_titre($langs->trans("SocialContributions"),($year?"".img_previous()." ".$langs->trans("Year")." $year ".img_next()."":"")); - } - else - { - print_barre_liste($langs->trans("SocialContributions"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$totalnboflines); - } - + + print_fiche_titre($langs->trans("Loans")); + if (empty($mysoc->country_id) && empty($mysoc->country_code)) { print '
'; @@ -125,24 +101,16 @@ if ($resql) print ""; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"id","",$param,"",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"cs.libelle","",$param,'align="left"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("PeriodEndDate"),$_SERVER["PHP_SELF"],"periode","",$param,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"cs.amount","",$param,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DateDue"),$_SERVER["PHP_SELF"],"cs.date_ech","",$param,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cs.paye","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"l.label","",$param,'align="left"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Capital"),$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"l.datestart","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"l.paid","",$param,'align="right"',$sortfield,$sortorder); print "\n"; print ''; print ' '; print ''; - // Type - print ''; - $formsocialcontrib->select_type_socialcontrib($typeid,'typeid',1,16,0); - print ''; - // Period end date print ' '; - print ' '; print ' '; print ''; print ''; @@ -161,33 +129,19 @@ if ($resql) $loan->id=$obj->id; $loan->lib=$obj->id; $loan->ref=$obj->id; - print $loan->getNomUrl(1,'20'); + print $loan->getNameUrl(1,'20'); print ''; // Label - print ''.dol_trunc($obj->libelle,42).''; + print ''.dol_trunc($obj->label,42).''; - // Type - print ''.dol_trunc($obj->type_lib,16).''; + // Capital + print ''.price($obj->capital).''; - // Date end period - print ''; - if ($obj->periode) - { - print 'jdate($obj->periode)).'">'.dol_print_date($db->jdate($obj->periode),'day').''; - } - else - { - print ' '; - } - print ''; + // Date start + print ''.dol_print_date($db->jdate($obj->datestart), 'day').''; - print ''.price($obj->amount).''; - - // Due date - print ''.dol_print_date($db->jdate($obj->date_ech), 'day').''; - - print ''.$loan->LibStatut($obj->paye,5,$obj->alreadypayed).''; + print ''.$loan->LibStatut($obj->paid,5,$obj->alreadypayed).''; print ''; $i++; From 3d23319226f5b4054151ba7d59fef1d2cdb76821 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Wed, 24 Sep 2014 04:10:29 +0200 Subject: [PATCH 06/24] Update --- htdocs/compta/loan/index.php | 103 +++++++++++++---------------- htdocs/compta/prelevement/list.php | 2 +- 2 files changed, 46 insertions(+), 59 deletions(-) diff --git a/htdocs/compta/loan/index.php b/htdocs/compta/loan/index.php index 41299668dd1..16b9a10c054 100644 --- a/htdocs/compta/loan/index.php +++ b/htdocs/compta/loan/index.php @@ -72,8 +72,8 @@ if ($filtre) { $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit+1,$offset); - $resql=$db->query($sql); + if ($resql) { $num = $db->num_rows($resql); @@ -84,73 +84,60 @@ if ($resql) print_fiche_titre($langs->trans("Loans")); - if (empty($mysoc->country_id) && empty($mysoc->country_code)) - { - print '
'; - $langs->load("errors"); - $countrynotdefined=$langs->trans("ErrorSetACountryFirst"); - print $countrynotdefined; - print '
'; - } - else + print '
'; + + print ""; + + print ""; + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"id","",$param,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"l.label","",$param,'align="left"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Capital"),$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"l.datestart","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"l.paid","",$param,'align="right"',$sortfield,$sortorder); + print "\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + while ($i < min($num,$limit)) { + $obj = $db->fetch_object($resql); - print ''; + $var = !$var; + print ""; - print "
   '; + print ''; + print '
"; - - print ""; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"id","",$param,"",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"l.label","",$param,'align="left"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Capital"),$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"l.datestart","",$param,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"l.paid","",$param,'align="right"',$sortfield,$sortorder); - print "\n"; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - while ($i < min($num,$limit)) - { - $obj = $db->fetch_object($resql); + // Label + print ''; - $var = !$var; - print ""; + // Capital + print ''; - // Ref - print ''; + // Date start + print ''; - // Label - print ''; + print ''; - // Capital - print ''; - - // Date start - print ''; - - print ''; - - print ''; - $i++; - } - - print '
   '; - print ''; + // Ref + print ''; + $loan->id=$obj->id; + $loan->label=$obj->id; + $loan->ref=$obj->id; + print $loan->getNameUrl(1,'20'); print '
'.dol_trunc($obj->label,42).'
'.price($obj->capital).''; - $loan->id=$obj->id; - $loan->lib=$obj->id; - $loan->ref=$obj->id; - print $loan->getNameUrl(1,'20'); - print ''.dol_print_date($db->jdate($obj->datestart), 'day').''.dol_trunc($obj->label,42).''.$loan->LibStatut($obj->paid,5,$obj->alreadypayed).''.price($obj->capital).''.dol_print_date($db->jdate($obj->datestart), 'day').''.$loan->LibStatut($obj->paid,5,$obj->alreadypayed).'
'; - - print '
'; + print ''; + $i++; } + + print ''; + print ''; } else { diff --git a/htdocs/compta/prelevement/list.php b/htdocs/compta/prelevement/list.php index 819d879b098..0608ea70431 100644 --- a/htdocs/compta/prelevement/list.php +++ b/htdocs/compta/prelevement/list.php @@ -120,7 +120,7 @@ if ($result) print ' '; print ''; - print '
'; + print ''; print ''; print ''; print ''; From d3252d1348cb736fe4cd4e809f313f9f30f76d82 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 29 Sep 2014 20:37:51 +0200 Subject: [PATCH 07/24] Update --- htdocs/compta/loan/card.php | 86 +++-- htdocs/compta/loan/class/loan.class.php | 76 +--- .../compta/loan/class/paymentloan.class.php | 168 +++------ htdocs/compta/loan/index.php | 48 ++- htdocs/compta/loan/payment.php | 331 ++++++++++++++++++ .../install/mysql/migration/3.6.0-3.7.0.sql | 42 +++ htdocs/install/mysql/tables/llx_loan.sql | 2 + 7 files changed, 498 insertions(+), 255 deletions(-) create mode 100644 htdocs/compta/loan/payment.php diff --git a/htdocs/compta/loan/card.php b/htdocs/compta/loan/card.php index 6b075e3d758..b3e31324cb0 100644 --- a/htdocs/compta/loan/card.php +++ b/htdocs/compta/loan/card.php @@ -367,42 +367,6 @@ if ($id > 0) dol_fiche_end(); - - /* - * Boutons actions - */ - if ($action != 'edit') - { - print "
\n"; - - // Edit - if ($user->rights->loan->write) - { - print "id&action=edit\">".$langs->trans("Modify").""; - } - - // Emettre paiement - if ($object->paye == 0 && ((price2num($object->amount) < 0 && round($resteapayer) < 0) || (price2num($object->amount) > 0 && round($resteapayer) > 0)) && $user->rights->loan->write) - { - print "id&action=create\">".$langs->trans("DoPayment").""; - } - - // Classify 'paid' - if ($object->paye == 0 && round($resteapayer) <=0 && $user->rights->loan->write) - { - print "id&action=paid\">".$langs->trans("ClassifyPaid").""; - } - - // Delete - if ($user->rights->loan->delete) - { - print "id&action=delete\">".$langs->trans("Delete").""; - } - - print "
"; - } - - print '
'; print ''; print ''; + print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''; print '\n"; - print "\n"; + print "\n"; print '\n"; print ""; - $totalpaye += $objp->amount; + $totalpaid += $objp->amount; $i++; } - if ($object->paye == 0) + if ($object->paid == 0) { - print "\n"; - print "\n"; + print "\n"; + print "\n"; - $resteapayer = $object->amount - $totalpaye; + $staytopay = $object->capital - $totalpaid; print ""; - print "\n"; + print "\n"; } print "
'; @@ -441,24 +405,24 @@ if ($id > 0) $objp = $db->fetch_object($resql); $var=!$var; print "
"; - print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$objp->paiement_type.' '.$objp->num_paiement."".$objp->paiement_type.' '.$objp->num_payment."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaye)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaid)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->capital)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("RemainderToPay")." :".price($resteapayer)." ".$langs->trans("Currency".$conf->currency)."
".price($staytopay)." ".$langs->trans("Currency".$conf->currency)."
"; $db->free($resql); @@ -469,6 +433,40 @@ if ($id > 0) } print ""; print ""; + + /* + * Boutons actions + */ + if ($action != 'edit') + { + print "
\n"; + + // Edit + if ($user->rights->loan->write) + { + print "id&action=edit\">".$langs->trans("Modify").""; + } + + // Emit payment + if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) + { + print "id&action=create\">".$langs->trans("DoPayment").""; + } + + // Classify 'paid' + if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write) + { + print "rowid&action=paid\">".$langs->trans("ClassifyPaid").""; + } + + // Delete + if ($user->rights->loan->delete) + { + print "id&action=delete\">".$langs->trans("Delete").""; + } + + print "
"; + } } else { diff --git a/htdocs/compta/loan/class/loan.class.php b/htdocs/compta/loan/class/loan.class.php index afd15ced451..a0cbf9a8224 100644 --- a/htdocs/compta/loan/class/loan.class.php +++ b/htdocs/compta/loan/class/loan.class.php @@ -33,6 +33,7 @@ class Loan extends CommonObject public $table_element='loan'; var $id; + var $rowid; var $ref; var $datestart; var $dateend; @@ -41,6 +42,7 @@ class Loan extends CommonObject var $nbterm; var $rate; var $note; + var $paid; var $account_capital; var $account_insurance; var $account_interest; @@ -71,7 +73,8 @@ class Loan extends CommonObject */ function fetch($id) { - $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note"; + $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note,"; + $sql.= " l.paid"; $sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; $sql.= " WHERE l.rowid = ".$id; @@ -92,6 +95,7 @@ class Loan extends CommonObject $this->nbterm = $obj->nbterm; $this->rate = $obj->rate; $this->note = $obj->note; + $this->paid = $obj->paid; return 1; } @@ -220,7 +224,7 @@ class Loan extends CommonObject // Delete payments if (! $error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge where fk_charge='".$this->id."'"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan='".$this->id."'"; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) @@ -232,7 +236,7 @@ class Loan extends CommonObject if (! $error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales where rowid='".$this->id."'"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid='".$this->id."'"; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) @@ -266,10 +270,10 @@ class Loan extends CommonObject { $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales"; - $sql.= " SET libelle='".$this->db->escape($this->lib)."',"; - $sql.= " date_ech='".$this->db->idate($this->date_ech)."',"; - $sql.= " periode='".$this->db->idate($this->periode)."'"; + $sql = "UPDATE ".MAIN_DB_PREFIX."loan"; + $sql.= " SET label='".$this->db->escape($this->label)."',"; + $sql.= " datestart='".$this->db->idate($this->datestart)."',"; + $sql.= " dateend='".$this->db->idate($this->dateend)."'"; $sql.= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::update", LOG_DEBUG); @@ -288,57 +292,15 @@ class Loan extends CommonObject } /** - * Enter description here ... - * - * @param int $year Year - * @return number - */ - function solde($year = 0) - { - global $conf; - - $sql = "SELECT SUM(f.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as f"; - $sql.= " WHERE f.entity = ".$conf->entity; - $sql.= " AND paye = 0"; - - if ($year) { - $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' "; - } - - $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - return $obj->amount; - } - else - { - return 0; - } - - $this->db->free($result); - - } - else - { - print $this->db->error(); - return -1; - } - } - - /** - * Tag social contribution as payed completely + * Tag loan as payed completely * * @param User $user Object user making change * @return int <0 if KO, >0 if OK */ function set_paid($user) { - $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET"; - $sql.= " paye = 1"; + $sql = "UPDATE ".MAIN_DB_PREFIX."loan SET"; + $sql.= " paid = 1"; $sql.= " WHERE rowid = ".$this->id; $return = $this->db->query($sql); if ($return) return 1; @@ -346,22 +308,22 @@ class Loan extends CommonObject } /** - * Retourne le libelle du statut d'une charge (impaye, payee) + * Return label of loan status (unpaid, paid) * - * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long + * @param int $mode 0=label, 1=short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) * @return string Label */ function getLibStatut($mode=0,$alreadypaid=-1) { - return $this->LibStatut($this->paye,$mode,$alreadypaid); + return $this->LibStatut($this->paid,$mode,$alreadypaid); } /** * Return label for given status * * @param int $statut Id statut - * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @param int $mode 0=Label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label, 5=Short label + Picto * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) * @return string Label */ @@ -425,7 +387,7 @@ class Loan extends CommonObject if (empty($this->ref)) $this->ref=$this->label; - $link = ''; + $link = ''; $linkend=''; if ($withpicto) $result.=($link.img_object($langs->trans("ShowLoan").': '.$this->label,'bill').$linkend.' '); diff --git a/htdocs/compta/loan/class/paymentloan.class.php b/htdocs/compta/loan/class/paymentloan.class.php index 24d59fb417b..c0cdb3cdb85 100644 --- a/htdocs/compta/loan/class/paymentloan.class.php +++ b/htdocs/compta/loan/class/paymentloan.class.php @@ -1,6 +1,5 @@ - * Copyright (C) 2004-2007 Laurent Destailleur +/* Copyright (C) 2014 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,9 +16,9 @@ */ /** - * \file htdocs/compta/sociales/class/paymentsocialcontribution.class.php + * \file htdocs/compta/loan/class/paymentloan.class.php * \ingroup facture - * \brief File of class to manage payment of social contributions + * \brief File of class to manage payment of loans */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; @@ -36,7 +35,7 @@ class PaymentLoan extends CommonObject var $id; var $ref; - var $fk_charge; + var $fk_loan; var $datec=''; var $tms=''; var $datep=''; @@ -74,18 +73,18 @@ class PaymentLoan extends CommonObject $now=dol_now(); - // Validate parametres - if (! $this->datepaye) + // Validate parameters + if (! $this->datepaid) { $this->error='ErrorBadValueForParameter'; return -1; } // Clean parameters - if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge); + if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan); if (isset($this->amount)) $this->amount=trim($this->amount); - if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement); - if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement); + if (isset($this->fk_typepayment)) $this->fk_typepaiement=trim($this->fk_typepayment); + if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); if (isset($this->note)) $this->note=trim($this->note); if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); @@ -101,26 +100,26 @@ class PaymentLoan extends CommonObject $totalamount = price2num($totalamount); // Check parameters - if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null + if ($totalamount == 0) return -1; // Negative amounts are accepted for reject prelevement but not null $this->db->begin(); if ($totalamount != 0) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount,"; - $sql.= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan (fk_loan, datec, datep, amount,"; + $sql.= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)"; $sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',"; - $sql.= " '".$this->db->idate($this->datepaye)."',"; + $sql.= " '".$this->db->idate($this->datepaid)."',"; $sql.= " ".$totalamount.","; - $sql.= " ".$this->paiementtype.", '".$this->db->escape($this->num_paiement)."', '".$this->db->escape($this->note)."', ".$user->id.","; + $sql.= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.","; $sql.= " 0)"; dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge"); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_loan"); } else { @@ -155,22 +154,22 @@ class PaymentLoan extends CommonObject global $langs; $sql = "SELECT"; $sql.= " t.rowid,"; - $sql.= " t.fk_charge,"; + $sql.= " t.fk_loan,"; $sql.= " t.datec,"; $sql.= " t.tms,"; $sql.= " t.datep,"; $sql.= " t.amount,"; - $sql.= " t.fk_typepaiement,"; - $sql.= " t.num_paiement,"; + $sql.= " t.fk_typepayment,"; + $sql.= " t.num_payment,"; $sql.= " t.note,"; $sql.= " t.fk_bank,"; $sql.= " t.fk_user_creat,"; $sql.= " t.fk_user_modif,"; $sql.= " pt.code as type_code, pt.libelle as type_libelle,"; $sql.= ' b.fk_account'; - $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."paiementcharge as t)"; + $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."payment_loan as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; - $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepaiement = pt.id"; + $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); @@ -183,13 +182,13 @@ class PaymentLoan extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->rowid; - $this->fk_charge = $obj->fk_charge; + $this->fk_loan = $obj->fk_loan; $this->datec = $this->db->jdate($obj->datec); $this->tms = $this->db->jdate($obj->tms); $this->datep = $this->db->jdate($obj->datep); $this->amount = $obj->amount; - $this->fk_typepaiement = $obj->fk_typepaiement; - $this->num_paiement = $obj->num_paiement; + $this->fk_typepayment = $obj->fk_typepayment; + $this->num_payment = $obj->num_payment; $this->note = $obj->note; $this->fk_bank = $obj->fk_bank; $this->fk_user_creat = $obj->fk_user_creat; @@ -227,36 +226,33 @@ class PaymentLoan extends CommonObject // Clean parameters - if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge); + if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan); if (isset($this->amount)) $this->amount=trim($this->amount); - if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement); - if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement); + if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); + if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); if (isset($this->note)) $this->note=trim($this->note); if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); - - // Check parameters // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET"; + $sql = "UPDATE ".MAIN_DB_PREFIX."payment_loan SET"; - $sql.= " fk_charge=".(isset($this->fk_charge)?$this->fk_charge:"null").","; + $sql.= " fk_loan=".(isset($this->fk_loan)?$this->fk_loan:"null").","; $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; - $sql.= " fk_typepaiement=".(isset($this->fk_typepaiement)?$this->fk_typepaiement:"null").","; - $sql.= " num_paiement=".(isset($this->num_paiement)?"'".$this->db->escape($this->num_paiement)."'":"null").","; + $sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").","; + $sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").","; $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").","; $sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").","; $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").","; $sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null").""; - $sql.= " WHERE rowid=".$this->id; $this->db->begin(); @@ -317,7 +313,7 @@ class PaymentLoan extends CommonObject if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; - $sql.= " WHERE type='payment_sc' AND url_id=".$this->id; + $sql.= " WHERE type='payment_loan' AND url_id=".$this->id; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql = $this->db->query($sql); @@ -326,7 +322,7 @@ class PaymentLoan extends CommonObject if (! $error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan"; $sql.= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::delete", LOG_DEBUG); @@ -368,96 +364,12 @@ class PaymentLoan extends CommonObject } } - - - /** - * Load an object from its id and create a new one in database - * - * @param int $fromid Id of object to clone - * @return int New id of clone - */ - function createFromClone($fromid) - { - global $user,$langs; - - $error=0; - - $object=new PaymentSocialContribution($this->db); - - $this->db->begin(); - - // Load source object - $object->fetch($fromid); - $object->id=0; - $object->statut=0; - - // Clear fields - // ... - - // Create clone - $result=$object->create($user); - - // Other options - if ($result < 0) - { - $this->error=$object->error; - $error++; - } - - if (! $error) - { - - - - } - - // End - if (! $error) - { - $this->db->commit(); - return $object->id; - } - else - { - $this->db->rollback(); - return -1; - } - } - - - /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void - */ - function initAsSpecimen() - { - $this->id=0; - - $this->fk_charge=''; - $this->datec=''; - $this->tms=''; - $this->datep=''; - $this->amount=''; - $this->fk_typepaiement=''; - $this->num_paiement=''; - $this->note=''; - $this->fk_bank=''; - $this->fk_user_creat=''; - $this->fk_user_modif=''; - - - } - - /** * Add record into bank for payment with links between this bank record and invoices of payment. * All payment properties must have been set first like after a call to create(). * * @param User $user Object of user making payment - * @param string $mode 'payment_sc' + * @param string $mode 'payment_loan' * @param string $label Label to use in bank record * @param int $accountid Id of bank account to do link with * @param string $emetteur_nom Name of transmitter @@ -482,11 +394,11 @@ class PaymentLoan extends CommonObject // Insert payment into llx_bank $bank_line_id = $acc->addline( - $this->datepaye, - $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example") + $this->datepaid, + $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example") $label, $total, - $this->num_paiement, + $this->num_payment, '', $user, $emetteur_nom, @@ -506,10 +418,10 @@ class PaymentLoan extends CommonObject // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction $url=''; - if ($mode == 'payment_sc') $url=DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='; + if ($mode == 'payment_loan') $url=DOL_URL_ROOT.'/compta/loan/payment/card.php?id='; if ($url) { - $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode); if ($result <= 0) { $error++; @@ -578,7 +490,7 @@ class PaymentLoan extends CommonObject * @param int $maxlen Longueur max libelle * @return string Chaine avec URL */ - function getNomUrl($withpicto=0,$maxlen=0) + function getNameUrl($withpicto=0,$maxlen=0) { global $langs; @@ -588,7 +500,7 @@ class PaymentLoan extends CommonObject if (!empty($this->id)) { - $lien = ''; + $lien = ''; $lienfin=''; if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$lienfin.' '); diff --git a/htdocs/compta/loan/index.php b/htdocs/compta/loan/index.php index 16b9a10c054..8bef47ff66e 100644 --- a/htdocs/compta/loan/index.php +++ b/htdocs/compta/loan/index.php @@ -41,17 +41,17 @@ if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -$limit = $conf->liste_limit; if (! $sortfield) $sortfield="l.rowid"; if (! $sortorder) $sortorder="DESC"; +$limit = $conf->liste_limit; +$search_label=GETPOST('search_label','alpha'); $filtre=$_GET["filtre"]; /* * View */ -$form = new Form($db); $loan = new Loan($db); llxHeader(); @@ -68,34 +68,29 @@ if ($filtre) { $filtre=str_replace(":","=",$filtre); $sql .= " AND ".$filtre; } - $sql.= $db->order($sortfield,$sortorder); -$sql.= $db->plimit($limit+1,$offset); +$sql.= $db->plimit($limit + 1, $offset); +//print $sql; $resql=$db->query($sql); - if ($resql) { $num = $db->num_rows($resql); - $i = 0; - $var=true; - $param=''; - print_fiche_titre($langs->trans("Loans")); - - print ''; - print ""; - - print ""; + $i = 0; + print ''."\n"; + print '
'; + print ''; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"id","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"l.label","",$param,'align="left"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Capital"),$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"l.datestart","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"l.paid","",$param,'align="right"',$sortfield,$sortorder); - print "\n"; + print "\n"; + // Filters lines print ''; print ''; print ''; @@ -103,9 +98,9 @@ if ($resql) print ''; print ''; - print "\n"; - + print "\n"; + + $var=true; while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); @@ -115,9 +110,9 @@ if ($resql) // Ref print ''; @@ -132,18 +127,19 @@ if ($resql) print ''; - print ''; + print "\n"; + $i++; } - print '
  '; print ''; - print '
'; - $loan->id=$obj->id; - $loan->label=$obj->id; - $loan->ref=$obj->id; + $loan->id=$obj->rowid; + $loan->label=$obj->rowid; + $loan->ref=$obj->rowid; print $loan->getNameUrl(1,'20'); print ''.$loan->LibStatut($obj->paid,5,$obj->alreadypayed).'
'; - print ''; + print ""; + print "\n"; + $db->free($resql); } else { - dol_print_error($db); + dol_print_error($db); } - $db->close(); llxFooter(); diff --git a/htdocs/compta/loan/payment.php b/htdocs/compta/loan/payment.php new file mode 100644 index 00000000000..a513ba212cd --- /dev/null +++ b/htdocs/compta/loan/payment.php @@ -0,0 +1,331 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/loan/payment.php + * \ingroup Loan + * \brief Page to add payment of a loan + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/paymentloan.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + +$langs->load("bills"); + +$chid=GETPOST("id"); +$action=GETPOST('action'); +$amounts = array(); + +// Security check +$socid=0; +if ($user->societe_id > 0) +{ + $socid = $user->societe_id; +} + +/* + * Actions + */ + +if ($action == 'add_payment') +{ + $error=0; + + if ($_POST["cancel"]) + { + $loc = DOL_URL_ROOT.'/compta/loan/card.php?id='.$chid; + header("Location: ".$loc); + exit; + } + + $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + + if (! $_POST["paymenttype"] > 0) + { + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")); + $error++; + } + if ($datepaid == '') + { + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date")); + $error++; + } + if (! empty($conf->banque->enabled) && ! $_POST["accountid"] > 0) + { + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit")); + $error++; + } + + if (! $error) + { + $paymentid = 0; + + // Read possible payments + foreach ($_POST as $key => $value) + { + if (substr($key,0,7) == 'amount_') + { + $other_chid = substr($key,7); + $amounts[$other_chid] = price2num($_POST[$key]); + } + } + + if (count($amounts) <= 0) + { + $error++; + $errmsg='ErrorNoPaymentDefined'; + } + + if (! $error) + { + $db->begin(); + + // Create a line of payments + $paiement = new PaymentSocialContribution($db); + $paiement->chid = $chid; + $paiement->datepaid = $datepaid; + $paiement->amounts = $amounts; // Tableau de montant + $paiement->paymenttype = $_POST["paymenttype"]; + $paiement->num_payment = $_POST["num_payment"]; + $paiement->note = $_POST["note"]; + + if (! $error) + { + $paymentid = $payment->create($user); + if ($paymentid < 0) + { + $errmsg=$paiement->error; + $error++; + } + } + + if (! $error) + { + $result=$paiement->addPaymentToBank($user,'payment_sc','(SocialContributionPayment)',$_POST['accountid'],'',''); + if (! $result > 0) + { + $errmsg=$paiement->error; + $error++; + } + } + + if (! $error) + { + $db->commit(); + $loc = DOL_URL_ROOT.'/compta/loan/card.php?id='.$chid; + header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); + } + } + } + + $_GET["action"]='create'; +} + + +/* + * View + */ + +llxHeader(); + +$form=new Form($db); + + +// Form to create loan's payment +if ($_GET["action"] == 'create') +{ + + $loan = new Loan($db); + $loan->fetch($chid); + + $total = $loan->capital; + + print_fiche_titre($langs->trans("DoPayment")); + print "
\n"; + + if ($mesg) + { + print "
$mesg
"; + } + + print '
'; + print ''; + print ''; + print ''; + print ''; + + print ''; + + print ""; + + print ''; + print '\n"; + print '\n"; + print ''; + + $sql = "SELECT sum(p.amount) as total"; + $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; + $sql.= " WHERE p.fk_loan = ".$chid; + $resql = $db->query($sql); + if ($resql) + { + $obj=$db->fetch_object($resql); + $sumpaid = $obj->total; + $db->free(); + } + print ''; + print ''; + print ''; + + print '
".$langs->trans("Loan")."
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("Period")."".dol_print_date($loan->datestart,'day')."
'.$langs->trans("Label").''.$loan->label."
'.$langs->trans("Amount")."".price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("AlreadyPaid").''.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'; + + print '
'; + + print ''; + print ''; + print "'; + print ''; + + print '"; + print ''; + + print '\n"; + print ''; + + print ''; + print ''; + print ''; + + // Number + print ''; + print ''."\n"; + + print ''; + print ''; + print ''; + print ''; + + print '
".$langs->trans("Payment").'
'.$langs->trans("Date").''; + $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0; + $form->select_date($datepayment,'','','','',"add_payment",1,1); + print "
'.$langs->trans("PaymentMode").''; + $form->select_types_paiements(isset($_POST["paymenttype"])?$_POST["paymenttype"]:$loan->paymenttype, "paymenttype"); + print "
'.$langs->trans('AccountToDebit').''; + $form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$charge->accountid, "accountid", 0, '',1); // Show opend bank account list + print '
'.$langs->trans('Number'); + print ' ('.$langs->trans("ChequeOrTransferNumber").')'; + print '
'.$langs->trans("Comments").'
'; + + print '
'; + + /* + * Autres charges impayees + */ + $num = 1; + $i = 0; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $var=True; + $total=0; + $totalrecu=0; + + while ($i < $num) + { + $objp = $loan; + + $var=!$var; + + print ""; + + if ($objp->datestart > 0) + { + print "\n"; + } + else + { + print "\n"; + } + + print '"; + + print '"; + + print '"; + + print '"; + + print "\n"; + $total+=$objp->total; + $total_ttc+=$objp->total_ttc; + $totalrecu+=$objp->am; + $i++; + } + if ($i > 1) + { + // Print total + print ""; + print ''; + print ""; + print ""; + print ""; + print ''; + print "\n"; + } + + print "
'.$langs->trans("DateDue").''.$langs->trans("Amount").''.$langs->trans("AlreadyPaid").''.$langs->trans("RemainderToPay").''.$langs->trans("Amount").'
".dol_print_date($objp->datestart,'day')."!!!'.price($objp->capital)."'.price($sumpaid)."'.price($objp->capital - $sumpaid)."'; + if ($sumpaid < $objp->capital) + { + $namef = "amount_".$objp->id; + print ''; + } + else + { + print '-'; + } + print "
'.$langs->trans("Total").':".price($total_ttc)."".price($totalrecu)."".price($total_ttc - $totalrecu)." 
"; + + print '
'; + + print ''; + print '   '; + print ''; + + print '
'; + + print "
\n"; +} + + +$db->close(); + +llxFooter(); diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 9e109cd311f..5bffbc0e5be 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -1083,3 +1083,45 @@ CREATE TABLE llx_usergroup_extrafields ( ) ENGINE=innodb; ALTER TABLE llx_usergroup_extrafields ADD INDEX idx_usergroup_extrafields (fk_object); + +-- Loan +create table llx_loan +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, + datec datetime, + tms timestamp, + label varchar(80) NOT NULL, + fk_bank integer, + capital real default 0 NOT NULL, + datestart date, + dateend date, + nbterm real, + rate double NOT NULL, + note text, + capital_position real default 0, + date_position date, + paid smallint default 0 NOT NULL, + accountancy_account_capital varchar(32), + accountancy_account_insurance varchar(32), + accountancy_account_interest varchar(32), + fk_user_author integer DEFAULT NULL, + fk_user_modif integer DEFAULT NULL, + active tinyint DEFAULT 1 NOT NULL +)ENGINE=innodb; + +create table llx_payment_loan +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_loan integer, + datec datetime, + tms timestamp, + datep datetime, + amount real DEFAULT 0, + fk_typepayment integer NOT NULL, + num_payment varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, + fk_user_modif integer +)ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_loan.sql b/htdocs/install/mysql/tables/llx_loan.sql index 2ca026ba417..bc152099a04 100644 --- a/htdocs/install/mysql/tables/llx_loan.sql +++ b/htdocs/install/mysql/tables/llx_loan.sql @@ -37,6 +37,8 @@ create table llx_loan capital_position real default 0, -- If not a new loan, just have the position of capital date_position date, + paid smallint default 0 NOT NULL, + accountancy_account_capital varchar(32), accountancy_account_insurance varchar(32), accountancy_account_interest varchar(32), From 3627f157d2d208882366ddd7615ed5eb0b2f525c Mon Sep 17 00:00:00 2001 From: aspangaro Date: Wed, 1 Oct 2014 07:16:29 +0200 Subject: [PATCH 08/24] Add langs & debug --- htdocs/compta/bank/account.php | 24 ++ htdocs/compta/loan/card.php | 25 +- htdocs/compta/loan/class/loan.class.php | 14 +- .../compta/loan/class/paymentloan.class.php | 62 ++-- htdocs/compta/loan/document.php | 4 +- htdocs/compta/loan/index.php | 4 +- htdocs/compta/loan/payment/card.php | 308 ++++++++++++++++++ htdocs/compta/loan/payment/index.html | 0 htdocs/compta/loan/{ => payment}/payment.php | 32 +- htdocs/langs/en_US/admin.lang | 6 + htdocs/langs/en_US/loan.lang | 15 + htdocs/langs/fr_FR/admin.lang | 6 + htdocs/langs/fr_FR/loan.lang | 15 + 13 files changed, 442 insertions(+), 73 deletions(-) create mode 100644 htdocs/compta/loan/payment/card.php create mode 100644 htdocs/compta/loan/payment/index.html rename htdocs/compta/loan/{ => payment}/payment.php (89%) create mode 100644 htdocs/langs/en_US/loan.lang create mode 100644 htdocs/langs/fr_FR/loan.lang diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index 14b586c6d80..57329e9e93b 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -37,6 +37,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php' require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; @@ -44,6 +45,7 @@ $langs->load("banks"); $langs->load("categories"); $langs->load("bills"); $langs->load("companies"); +$langs->load("loan"); $id = (GETPOST('id','int') ? GETPOST('id','int') : GETPOST('account','int')); $ref = GETPOST('ref','alpha'); @@ -148,6 +150,7 @@ llxHeader(); $societestatic=new Societe($db); $userstatic=new User($db); $chargestatic=new ChargeSociales($db); +$loanstatic=new Loan($db); $memberstatic=new Adherent($db); $paymentstatic=new Paiement($db); $paymentsupplierstatic=new PaiementFourn($db); @@ -606,6 +609,12 @@ if ($id > 0 || ! empty($ref)) $paymentsalstatic->ref=$links[$key]['url_id']; print ' '.$paymentsalstatic->getNomUrl(2); } + elseif ($links[$key]['type']=='payment_loan') + { + print ''; + print ' '.img_object($langs->trans('ShowPayment'),'payment').' '; + print ''; + } elseif ($links[$key]['type']=='banktransfert') { // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail. @@ -705,6 +714,21 @@ if ($id > 0 || ! empty($ref)) $chargestatic->ref=$chargestatic->lib; print $chargestatic->getNomUrl(1,16); } + else if ($links[$key]['type']=='loan') + { + $loanstatic->id=$links[$key]['url_id']; + if (preg_match('/^\((.*)\)$/i',$links[$key]['label'],$reg)) + { + if ($reg[1]=='loan') $reg[1]='Loan'; + $loanstatic->label=$langs->trans($reg[1]); + } + else + { + $loanstatic->label=$links[$key]['label']; + } + $loanstatic->ref=$loanstatic->label; + print $loanstatic->getNameUrl(1,16); + } else if ($links[$key]['type']=='member') { $memberstatic->id=$links[$key]['url_id']; diff --git a/htdocs/compta/loan/card.php b/htdocs/compta/loan/card.php index b3e31324cb0..d2dc5362915 100644 --- a/htdocs/compta/loan/card.php +++ b/htdocs/compta/loan/card.php @@ -116,16 +116,16 @@ if ($action == 'add' && $user->rights->loan->write) if ($action == 'update' && ! $_POST["cancel"] && $user->rights->loan->write) { - $dateech=dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]); - $dateperiod=dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]); - if (! $dateech) + $datestart=dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); + $dateend=dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); + if (! $datestart) { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors'); + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); $action = 'edit'; } - elseif (! $dateperiod) + elseif (! $dateend) { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors'); + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors'); $action = 'edit'; } else @@ -298,7 +298,7 @@ if ($id > 0) print ''; // Ref - print '"; @@ -360,10 +360,9 @@ if ($id > 0) print ''; print '   '; print ''; - print '\n"; + print ''; + print ''; + } dol_fiche_end(); @@ -450,13 +449,13 @@ if ($id > 0) // Emit payment if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) { - print "id&action=create\">".$langs->trans("DoPayment").""; + print "id&action=create\">".$langs->trans("DoPayment").""; } // Classify 'paid' if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write) { - print "rowid&action=paid\">".$langs->trans("ClassifyPaid").""; + print "id&action=paid\">".$langs->trans("ClassifyPaid").""; } // Delete diff --git a/htdocs/compta/loan/class/loan.class.php b/htdocs/compta/loan/class/loan.class.php index a0cbf9a8224..07b842b708e 100644 --- a/htdocs/compta/loan/class/loan.class.php +++ b/htdocs/compta/loan/class/loan.class.php @@ -87,7 +87,7 @@ class Loan extends CommonObject $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; - $this->ref = $obj->rowid; + $this->ref = $obj->rowid; $this->datestart = $this->db->jdate($obj->datestart); $this->dateend = $this->db->jdate($obj->dateend); $this->label = $obj->label; @@ -114,7 +114,7 @@ class Loan extends CommonObject /** - * Create a social contribution into database + * Create a loan into database * * @param User $user User making creation * @return int <0 if KO, id if OK @@ -201,10 +201,10 @@ class Loan extends CommonObject $this->db->begin(); - // Get bank transaction lines for this social contributions + // Get bank transaction lines for this loan include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $account=new Account($this->db); - $lines_url=$account->get_url('',$this->id,'sc'); + $lines_url=$account->get_url('',$this->id,'loan'); // Delete bank urls foreach ($lines_url as $line_url) @@ -385,14 +385,12 @@ class Loan extends CommonObject $result=''; - if (empty($this->ref)) $this->ref=$this->label; - - $link = ''; + $link = ''; $linkend=''; if ($withpicto) $result.=($link.img_object($langs->trans("ShowLoan").': '.$this->label,'bill').$linkend.' '); if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend; + if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->label,$maxlen):$this->label).$linkend; return $result; } diff --git a/htdocs/compta/loan/class/paymentloan.class.php b/htdocs/compta/loan/class/paymentloan.class.php index c0cdb3cdb85..0a558fc9bf4 100644 --- a/htdocs/compta/loan/class/paymentloan.class.php +++ b/htdocs/compta/loan/class/paymentloan.class.php @@ -24,8 +24,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; -/** \class PaymentSocialContribution - * \brief Class to manage payments of social contributions +/** \class PaymentLoan + * \brief Class to manage payments of loans */ class PaymentLoan extends CommonObject { @@ -41,8 +41,8 @@ class PaymentLoan extends CommonObject var $datep=''; var $amount; // Total amount of payment var $amounts=array(); // Array of amounts - var $fk_typepaiement; - var $num_paiement; + var $fk_typepayment; + var $num_payment; var $note; var $fk_bank; var $fk_user_creat; @@ -59,7 +59,7 @@ class PaymentLoan extends CommonObject } /** - * Create payment of social contribution into database. + * Create payment of loan into database. * Use this->amounts to have list of lines for the payment * * @param User $user User making payment @@ -81,14 +81,14 @@ class PaymentLoan extends CommonObject } // Clean parameters - if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan); - if (isset($this->amount)) $this->amount=trim($this->amount); - if (isset($this->fk_typepayment)) $this->fk_typepaiement=trim($this->fk_typepayment); - if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); - if (isset($this->note)) $this->note=trim($this->note); - if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); - if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); - if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan); + if (isset($this->amount)) $this->amount = trim($this->amount); + if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); + if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); + if (isset($this->note)) $this->note = trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif); $totalamount = 0; foreach ($this->amounts as $key => $value) // How payment is dispatch @@ -390,7 +390,7 @@ class PaymentLoan extends CommonObject $acc->fetch($accountid); $total=$this->total; - if ($mode == 'payment_sc') $total=-$total; + if ($mode == 'payment_loan') $total=-$total; // Insert payment into llx_bank $bank_line_id = $acc->addline( @@ -405,8 +405,8 @@ class PaymentLoan extends CommonObject $emetteur_banque ); - // Mise a jour fk_bank dans llx_paiement. - // On connait ainsi le paiement qui a genere l'ecriture bancaire + // Update fk_bank into llx_paiement. + // We know the payment who generated the account write if ($bank_line_id > 0) { $result=$this->update_fk_bank($bank_line_id); @@ -416,7 +416,7 @@ class PaymentLoan extends CommonObject dol_print_error($this->db); } - // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction + // Add link 'payment_loan' in bank_url between payment and bank transaction $url=''; if ($mode == 'payment_loan') $url=DOL_URL_ROOT.'/compta/loan/payment/card.php?id='; if ($url) @@ -433,11 +433,11 @@ class PaymentLoan extends CommonObject $linkaddedforthirdparty=array(); foreach ($this->amounts as $key => $value) { - if ($mode == 'payment_sc') + if ($mode == 'payment_loan') { - $socialcontrib = new ChargeSociales($this->db); - $socialcontrib->fetch($key); - $result=$acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc'); + $loan = new Loan($this->db); + $loan->fetch($key); + $result=$acc->add_url_line($bank_line_id, $loan->id, DOL_URL_ROOT.'/compta/loan/card.php?id=', $loan->type_libelle.(($loan->lib && $loan->lib!=$loan->type_libelle)?' ('.$loan->lib.')':''),'loan'); if ($result <= 0) dol_print_error($this->db); } } @@ -461,14 +461,14 @@ class PaymentLoan extends CommonObject /** - * Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee + * Update link between loan's payment and the line generate in llx_bank * * @param int $id_bank Id if bank * @return int >0 if OK, <=0 if KO */ function update_fk_bank($id_bank) { - $sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id; + $sql = "UPDATE ".MAIN_DB_PREFIX."payment_loan SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG); $result = $this->db->query($sql); @@ -484,11 +484,11 @@ class PaymentLoan extends CommonObject } /** - * Renvoie nom clicable (avec eventuellement le picto) + * Return clicable name (with eventually a picto) * - * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul - * @param int $maxlen Longueur max libelle - * @return string Chaine avec URL + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=No picto + * @param int $maxlen Max length label + * @return string Chaine with URL */ function getNameUrl($withpicto=0,$maxlen=0) { @@ -500,12 +500,12 @@ class PaymentLoan extends CommonObject if (!empty($this->id)) { - $lien = ''; - $lienfin=''; + $link = ''; + $linkend=''; - if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$lienfin.' '); + if ($withpicto) $result.=($link.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$linkend.' '); if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$lien.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$lienfin; + if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend; } return $result; diff --git a/htdocs/compta/loan/document.php b/htdocs/compta/loan/document.php index 022340270ad..b263fa1687d 100644 --- a/htdocs/compta/loan/document.php +++ b/htdocs/compta/loan/document.php @@ -119,7 +119,7 @@ if ($object->id) print ''; // Date start - print ""; + print ""; print ""; // Date end - print ""; + print ""; print "'; diff --git a/htdocs/compta/loan/payment/card.php b/htdocs/compta/loan/payment/card.php new file mode 100644 index 00000000000..d08c5f8ce0f --- /dev/null +++ b/htdocs/compta/loan/payment/card.php @@ -0,0 +1,308 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/loan/payment/card.php + * \ingroup loan + * \brief Payment's card of loan + */ + +require '../../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/paymentloan.class.php'; +// require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +// require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; +if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + +$langs->load('bills'); +$langs->load('banks'); +$langs->load('companies'); +$langs->load('loan'); + +// Security check +$id=GETPOST("id"); +$action=GETPOST("action"); +$confirm=GETPOST('confirm'); +if ($user->societe_id) $socid=$user->societe_id; +// TODO ajouter regle pour restreindre acces paiement +//$result = restrictedArea($user, 'facture', $id,''); + +$payment = new PaymentLoan($db); +if ($id > 0) +{ + $result=$payment->fetch($id); + if (! $result) dol_print_error($db,'Failed to get payment id '.$id); +} + + +/* + * Actions + */ + +// Delete payment +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->delete) +{ + $db->begin(); + + $result = $payment->delete($user); + if ($result > 0) + { + $db->commit(); + header("Location: ".DOL_URL_ROOT."/compta/loan/index.php"); + exit; + } + else + { + setEventMessage($payment->error, 'errors'); + $db->rollback(); + } +} + +// Create payment +if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->loan->write) +{ + $db->begin(); + + $result=$payment->valide(); + + if ($result > 0) + { + $db->commit(); + + $factures=array(); // TODO Get all id of invoices linked to this payment + foreach($factures as $id) + { + $fac = new Facture($db); + $fac->fetch($id); + + $outputlangs = $langs; + if (! empty($_REQUEST['lang_id'])) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $fac->generateDocument($fac->modelpdf, $outputlangs); + } + } + + header('Location: card.php?id='.$payment->id); + exit; + } + else + { + setEventMessage($payment->error); + $db->rollback(); + } +} + + +/* + * View + */ + +llxHeader(); + +$loan = new Loan($db); + +$form = new Form($db); + +$h=0; + +$head[$h][0] = DOL_URL_ROOT.'/compta/loan/payment/card.php?id='.$_GET["id"]; +$head[$h][1] = $langs->trans("Card"); +$hselected = $h; +$h++; + +dol_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), 0, 'payment'); + +/* + * Confirm deletion of the payment + */ +if ($action == 'delete') +{ + print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); + +} + +/* + * Confirm validation of the payment + */ +if ($action == 'valide') +{ + $facid = $_GET['facid']; + print $form->formconfirm('card.php?id='.$payment->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); + +} + + +print '
'.$langs->trans("Ref").''; + print '
'.$langs->trans("Ref").''; print $form->showrefnav($object,'id'); print "
'.$langs->trans("Capital").''.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).'
".$langs->trans("Datestart")."
".$langs->trans("DateStart").""; if ($action == 'edit') { @@ -133,7 +133,7 @@ if ($object->id) print "
".$langs->trans("Dateend")."
".$langs->trans("DateEnd").""; if ($action == 'edit') { diff --git a/htdocs/compta/loan/index.php b/htdocs/compta/loan/index.php index 8bef47ff66e..a4432ba9ced 100644 --- a/htdocs/compta/loan/index.php +++ b/htdocs/compta/loan/index.php @@ -110,9 +110,7 @@ if ($resql) // Ref print ''; - $loan->id=$obj->rowid; - $loan->label=$obj->rowid; - $loan->ref=$obj->rowid; + $loan->id = $obj->id; print $loan->getNameUrl(1,'20'); print '
'; + +// Ref +print ''; +print ''; + +// Date +print ''; + +// Mode +print ''; + +// Number +print ''; + +// Amount +print ''; + +// Note +print ''; + +// Bank account +if (! empty($conf->banque->enabled)) +{ + if ($payment->bank_account) + { + $bankline=new AccountLine($db); + $bankline->fetch($payment->bank_line); + + print ''; + print ''; + print ''; + print ''; + } +} + +print '
'.$langs->trans('Ref').''; +print $form->showrefnav($payment,'id','',1,'rowid','id'); +print '
'.$langs->trans('Date').''.dol_print_date($payment->datep,'day').'
'.$langs->trans('Mode').''.$langs->trans("PaymentType".$payment->type_code).'
'.$langs->trans('Number').''.$payment->num_payment.'
'.$langs->trans('Amount').''.price($payment->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Note').''.nl2br($payment->note).'
'.$langs->trans('BankTransactionLine').''; + print $bankline->getNomUrl(1,0,'showall'); + print '
'; + + +/* + * List of loans payed + */ + +$disable_delete = 0; +$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount'; +$sql.= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l'; +$sql.= ' WHERE pl.fk_loan = l.rowid'; +$sql.= ' AND l.entity = '.$conf->entity; +$sql.= ' AND pl.rowid = '.$payment->id; + +dol_syslog("compta/loan/payment/card.php", LOG_DEBUG); +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + + $i = 0; + $total = 0; + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + if ($num > 0) + { + $var=True; + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + $var=!$var; + print ''; + // Ref + print '\n"; + // Label + print ''; + // Expected to pay + print ''; + // Status + print ''; + // Amount payed + print ''; + print "\n"; + if ($objp->paye == 1) // If at least one invoice is paid, disable delete + { + $disable_delete = 1; + } + $total = $total + $objp->amount; + $i++; + } + } + $var=!$var; + + print "
'.$langs->trans('Loan').''.$langs->trans('Label').''.$langs->trans('ExpectedToPay').''.$langs->trans('Status').''.$langs->trans('PayedByThisPayment').'
'; + $loan->fetch($objp->id); + print $loan->getNameUrl(1); + print "'.$objp->label.''.price($objp->capital).''.$loan->getLibStatut(4,$objp->amount).''.price($objp->amount).'
\n"; + $db->free($resql); +} +else +{ + dol_print_error($db); +} + +print '
'; + + +/* + * Boutons Actions + */ +print '
'; + +/* +if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) +{ + if ($user->societe_id == 0 && $payment->statut == 0 && $_GET['action'] == '') + { + if ($user->rights->facture->paiement) + { + print ''.$langs->trans('Valid').''; + } + } +} +*/ + +if ($_GET['action'] == '') +{ + if ($user->rights->loan->delete) + { + if (! $disable_delete) + { + print ''.$langs->trans('Delete').''; + } + else + { + print ''.$langs->trans('Delete').''; + } + } +} + +print '
'; + + + +llxFooter(); + +$db->close(); diff --git a/htdocs/compta/loan/payment/index.html b/htdocs/compta/loan/payment/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/compta/loan/payment.php b/htdocs/compta/loan/payment/payment.php similarity index 89% rename from htdocs/compta/loan/payment.php rename to htdocs/compta/loan/payment/payment.php index a513ba212cd..ed249d8f246 100644 --- a/htdocs/compta/loan/payment.php +++ b/htdocs/compta/loan/payment/payment.php @@ -21,12 +21,13 @@ * \brief Page to add payment of a loan */ -require '../../main.inc.php'; +require '../../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/paymentloan.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load("bills"); +$langs->load("loan"); $chid=GETPOST("id"); $action=GETPOST('action'); @@ -42,7 +43,6 @@ if ($user->societe_id > 0) /* * Actions */ - if ($action == 'add_payment') { $error=0; @@ -97,30 +97,30 @@ if ($action == 'add_payment') $db->begin(); // Create a line of payments - $paiement = new PaymentSocialContribution($db); - $paiement->chid = $chid; - $paiement->datepaid = $datepaid; - $paiement->amounts = $amounts; // Tableau de montant - $paiement->paymenttype = $_POST["paymenttype"]; - $paiement->num_payment = $_POST["num_payment"]; - $paiement->note = $_POST["note"]; + $payment = new PaymentLoan($db); + $payment->chid = $chid; + $payment->datepaid = $datepaid; + $payment->amounts = $amounts; // Tableau de montant + $payment->paymenttype = $_POST["paymenttype"]; + $payment->num_payment = $_POST["num_payment"]; + $payment->note = $_POST["note"]; if (! $error) { $paymentid = $payment->create($user); if ($paymentid < 0) { - $errmsg=$paiement->error; + $errmsg=$payment->error; $error++; } } if (! $error) { - $result=$paiement->addPaymentToBank($user,'payment_sc','(SocialContributionPayment)',$_POST['accountid'],'',''); + $result=$payment->addPaymentToBank($user,'payment_loan','(LoanPayment)',$_POST['accountid'],'',''); if (! $result > 0) { - $errmsg=$paiement->error; + $errmsg=$payment->error; $error++; } } @@ -180,7 +180,7 @@ if ($_GET["action"] == 'create') print "".$langs->trans("Loan").""; print ''.$langs->trans("Ref").''.$chid.''; - print ''.$langs->trans("Period")."".dol_print_date($loan->datestart,'day')."\n"; + print ''.$langs->trans("DateStart")."".dol_print_date($loan->datestart,'day')."\n"; print ''.$langs->trans("Label").''.$loan->label."\n"; print ''.$langs->trans("Amount")."".price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).''; @@ -222,14 +222,14 @@ if ($_GET["action"] == 'create') print ''; print ''.$langs->trans('AccountToDebit').''; print ''; - $form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$charge->accountid, "accountid", 0, '',1); // Show opend bank account list + $form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$loan->accountid, "accountid", 0, '',1); // Show opend bank account list print ''; // Number print ''.$langs->trans('Number'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print ''; - print ''."\n"; + print ''."\n"; print ''; print ''.$langs->trans("Comments").''; @@ -241,7 +241,7 @@ if ($_GET["action"] == 'create') print '
'; /* - * Autres charges impayees + * Other loan unpaid */ $num = 1; $i = 0; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index fae312ee8e8..7650b14950e 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -483,6 +483,8 @@ Module500Name=Special expenses (tax, social contributions, dividends) Module500Desc=Management of special expenses like taxes, social contribution, dividends and salaries Module510Name=Salaries Module510Desc=Management of employees salaries and payments +Module520Name=Loan +Module520Desc=Management of loans Module600Name=Notifications Module600Desc=Send notifications by email on some Dolibarr business events to third party contacts Module700Name=Donations @@ -696,6 +698,10 @@ Permission510=Read Salaries Permission512=Create/modify salaries Permission514=Delete salaries Permission517=Export salaries +Permission520=Read Loans +Permission522=Create/modify loans +Permission524=Delete loans +Permission527=Export loans Permission531=Read services Permission532=Create/modify services Permission534=Delete services diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang new file mode 100644 index 00000000000..6be2f13a101 --- /dev/null +++ b/htdocs/langs/en_US/loan.lang @@ -0,0 +1,15 @@ +# Dolibarr language file - Source file is en_US - loan +Loan=Loan +Loans=Loans +NewLoan=New Loan +ShowLoan=Show Loan +PaymentLoan=Loan payment +Capital=Capital +Nbterms=Number of terms +LoanAccountancyCapitalCode=Accountancy code capital +LoanAccountancyInsuranceCode=Accountancy code insurance +LoanAccountancyInterestCode=Accountancy code interest +ConfigLoan=Configuration of the module loan +LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Accountancy code capital by default +LOAN_ACCOUNTING_ACCOUNT_INTEREST=Accountancy code interest by default +LOAN_ACCOUNTING_ACCOUNT_INSURANCE=Accountancy code insurance by default \ No newline at end of file diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 0ea2d9d51f4..d8f1e3b0c16 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -482,6 +482,8 @@ Module500Name=Dépenses spéciales (taxes, charges, dividendes) Module500Desc=Gestion des dépenses spéciales comme les taxes, charges sociales et dividendes Module510Name=Salaires Module510Desc=Gestion des paiements des salaires des employés +Module520Name=Emprunts +Module520Desc=Suivi des emprunts Module600Name=Notifications Module600Desc=Envoi de notifications (par email) aux contacts de tiers sur certains événements métiers Module700Name=Dons @@ -695,6 +697,10 @@ Permission510=Consulter les salaires Permission512=Créer/modifier les salaires Permission514=Supprimer les salaires Permission517=Exporter les salaires +Permission520=Consulter les emprunts +Permission522=Créer/modifier les emprunts +Permission524=Supprimer les emprunts +Permission527=Exporter les emprunts Permission531=Consulter les services Permission532=Créer/modifier les services Permission534=Supprimer les services diff --git a/htdocs/langs/fr_FR/loan.lang b/htdocs/langs/fr_FR/loan.lang new file mode 100644 index 00000000000..d230f7f0582 --- /dev/null +++ b/htdocs/langs/fr_FR/loan.lang @@ -0,0 +1,15 @@ +# Dolibarr language file - Source file is en_US - loan +Loan=Emprunt +Loans=Emprunts +NewLoan=Nouvel emprunt +ShowLoan=Voir emprunt +PaymentLoan=Règlement d'emprunt +Capital=Capital +Nbterms=Nombre d'échéances +LoanAccountancyCapitalCode=Compte comptable capital +LoanAccountancyInsuranceCode=Compte comptable assurance +LoanAccountancyInterestCode=Compte comptable intérêts +ConfigLoan=Configuration du module emprunt +LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Compte comptable capital par défaut +LOAN_ACCOUNTING_ACCOUNT_INTEREST=Compte comptable intérêts par défaut +LOAN_ACCOUNTING_ACCOUNT_INSURANCE=Compte comptable assurance par défaut \ No newline at end of file From a0b4a0a3cd33eb1c5926f50aad858ada3f835e22 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Wed, 1 Oct 2014 07:32:03 +0200 Subject: [PATCH 09/24] Update menu auguria --- htdocs/core/menus/init_menu_auguria.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index 36a59d33109..3dfa9a546ba 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -12,7 +12,7 @@ insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, left insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('societe|fournisseur', '( ! empty($conf->societe->enabled) && (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))) || ! empty($conf->fournisseur->enabled)', 2__+MAX_llx_menu__, __HANDLER__, 'top', 'companies', '', 0, '/societe/index.php?mainmenu=companies&leftmenu=', 'ThirdParties', -1, 'companies', '$user->rights->societe->lire || $user->rights->societe->contact->lire', '', 2, 20, __ENTITY__); insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('product|service', '$conf->product->enabled || $conf->service->enabled', 3__+MAX_llx_menu__, __HANDLER__, 'top', 'products', '', 0, '/product/index.php?mainmenu=products&leftmenu=', 'Products/Services', -1, 'products', '$user->rights->produit->lire||$user->rights->service->lire', '', 0, 30, __ENTITY__); insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('propal|commande|fournisseur|contrat|ficheinter', '$conf->comptabilite->enabled || $conf->accounting->enabled || $conf->facture->enabled || $conf->deplacement->enabled || $conf->don->enabled || $conf->tax->enabled', 5__+MAX_llx_menu__, __HANDLER__, 'top', 'commercial', '', 0, '/comm/index.php?mainmenu=commercial&leftmenu=', 'Commercial', -1, 'commercial', '$user->rights->societe->lire || $user->rights->societe->contact->lire', '', 2, 40, __ENTITY__); -insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('comptabilite|accounting|facture|deplacement|don|tax|salaries', '$conf->comptabilite->enabled || $conf->accounting->enabled || $conf->facture->enabled || $conf->deplacement->enabled || $conf->don->enabled || $conf->tax->enabled || $conf->salaries->enabled', 6__+MAX_llx_menu__, __HANDLER__, 'top', 'accountancy', '', 0, '/compta/index.php?mainmenu=accountancy&leftmenu=', 'MenuFinancial', -1, 'compta', '$user->rights->compta->resultat->lire || $user->rights->accounting->plancompte->lire || $user->rights->facture->lire|| $user->rights->deplacement->lire || $user->rights->don->lire || $user->rights->tax->charges->lire || $user->rights->salaries->read', '', 2, 50, __ENTITY__); +insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('comptabilite|accounting|facture|deplacement|don|tax|salaries|loan', '$conf->comptabilite->enabled || $conf->accounting->enabled || $conf->facture->enabled || $conf->deplacement->enabled || $conf->don->enabled || $conf->tax->enabled || $conf->salaries->enabled || $conf->loan->enabled', 6__+MAX_llx_menu__, __HANDLER__, 'top', 'accountancy', '', 0, '/compta/index.php?mainmenu=accountancy&leftmenu=', 'MenuFinancial', -1, 'compta', '$user->rights->compta->resultat->lire || $user->rights->accounting->plancompte->lire || $user->rights->facture->lire|| $user->rights->deplacement->lire || $user->rights->don->lire || $user->rights->tax->charges->lire || $user->rights->salaries->read || $user->rights->loan->read', '', 2, 50, __ENTITY__); insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('banque|prelevement', '$conf->banque->enabled || $conf->prelevement->enabled', 14__+MAX_llx_menu__, __HANDLER__, 'top', 'bank', '', 0, '/compta/bank/index.php?mainmenu=bank&leftmenu=bank', 'MenuBankCash', -1, 'banks', '$user->rights->banque->lire || $user->rights->prelevement->bons->lire', '', 0, 60, __ENTITY__); insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('projet', '$conf->projet->enabled', 7__+MAX_llx_menu__, __HANDLER__, 'top', 'project', '', 0, '/projet/index.php?mainmenu=project&leftmenu=', 'Projects', -1, 'projects', '$user->rights->projet->lire', '', 2, 70, __ENTITY__); insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('mailing|export|import|opensurvey', '$conf->mailing->enabled || $conf->export->enabled || $conf->import->enabled || $conf->opensurvey->enabled', 8__+MAX_llx_menu__, __HANDLER__, 'top', 'tools', '', 0, '/core/tools.php?mainmenu=tools&leftmenu=', 'Tools', -1, 'other', '$user->rights->mailing->lire || $user->rights->export->lire || $user->rights->import->run || $user->rights->opensurvey->read', '', 2, 90, __ENTITY__); @@ -179,6 +179,9 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled', __HANDLER__, 'left', 2210__+MAX_llx_menu__, 'accountancy', 'tax_sal', 2200__+MAX_llx_menu__, '/compta/salaries/index.php?leftmenu=tax_salary&mainmenu=accountancy', 'Salaries', 1, 'salaries', '$user->rights->salaries->read', '', 0, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled && $leftmenu=="tax_salary"', __HANDLER__, 'left', 2211__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/salaries/card.php?leftmenu=tax_salary&action=create', 'NewPayment', 2, 'companies', '$user->rights->salaries->write', '', 0, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled && $leftmenu=="tax_salary"', __HANDLER__, 'left', 2212__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/salaries/index.php?leftmenu=tax_salary', 'Payments', 2, 'companies', '$user->rights->salaries->read', '', 0, 3, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled', __HANDLER__, 'left', 2220__+MAX_llx_menu__, 'accountancy', 'tax_loan', 2200__+MAX_llx_menu__, '/compta/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy', 'Loans', 1, 'loan', '$user->rights->loan->read', '', 0, 1, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2221__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/loan/card.php?leftmenu=tax_loan&action=create', 'NewLoan', 2, 'loan', '$user->rights->loan->write', '', 0, 2, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2222__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/loan/index.php?leftmenu=tax_loan', 'Payments', 2, 'companies', '$user->rights->loan->read', '', 0, 3, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled', __HANDLER__, 'left', 2250__+MAX_llx_menu__, 'accountancy', 'tax_social', 2200__+MAX_llx_menu__, '/compta/sociales/index.php?leftmenu=tax_social', 'SocialContributions', 1, '', '$user->rights->tax->charges->lire', '', 0, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled && $leftmenu=="tax_social"', __HANDLER__, 'left', 2251__+MAX_llx_menu__, 'accountancy', '', 2250__+MAX_llx_menu__, '/compta/sociales/charges.php?leftmenu=tax_social&action=create', 'MenuNewSocialContribution', 2, '', '$user->rights->tax->charges->creer', '', 0, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled && $leftmenu=="tax_social"', __HANDLER__, 'left', 2252__+MAX_llx_menu__, 'accountancy', '', 2250__+MAX_llx_menu__, '/compta/charges/index.php?leftmenu=tax_social&mainmenu=accountancy&mode=sconly', 'Payments', 2, '', '$user->rights->tax->charges->lire', '', 0, 3, __ENTITY__); From ba7a4d6f8802fda8adcedd6e2cdb2aac7f4ae069 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Thu, 2 Oct 2014 19:56:41 +0200 Subject: [PATCH 10/24] Update card --- htdocs/compta/loan/card.php | 87 ++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/htdocs/compta/loan/card.php b/htdocs/compta/loan/card.php index d2dc5362915..c97ca6d84b0 100644 --- a/htdocs/compta/loan/card.php +++ b/htdocs/compta/loan/card.php @@ -31,8 +31,9 @@ $langs->load("bills"); $langs->load("loan"); $id=GETPOST('id','int'); -$action=GETPOST("action"); +$action=GETPOST('action'); $confirm=GETPOST('confirm'); +$cancel=GETPOST('cancel'); // Security check $socid = GETPOST('socid','int'); @@ -46,17 +47,17 @@ $result = restrictedArea($user, 'loan', $id, '',''); // Classify paid if ($action == 'confirm_paid' && $confirm == 'yes') { - $loan = new Loan($db); - $loan->fetch($id); - $result = $loan->set_paid($user); + $object = new Loan($db); + $object->fetch($id); + $result = $object->set_paid($user); } // Delete loan if ($action == 'confirm_delete' && $confirm == 'yes') { - $loan = new Loan($db); - $loan->fetch($id); - $result=$loan->delete($user); + $object = new Loan($db); + $object->fetch($id); + $result=$object->delete($user); if ($result > 0) { header("Location: index.php"); @@ -72,8 +73,8 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // Add loan if ($action == 'add' && $user->rights->loan->write) { - $datestart=dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); - $dateend=dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); + $datestart=dol_mktime(12,0,0, $GETPOST("startmonth"), $GETPOST("startday"), $GETPOST("startyear")); + $dateend=dol_mktime(12,0,0, $GETPOST("endmonth"), $GETPOST("endday"), $GETPOST("endyear")); if (! $datestart) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); @@ -91,33 +92,33 @@ if ($action == 'add' && $user->rights->loan->write) } else { - $loan = new Loan($db); + $object = new Loan($db); - $loan->label = GETPOST("label"); - $loan->fk_bank = GETPOST("accountid"); - $loan->capital = GETPOST("capital"); - $loan->datestart = $datestart; - $loan->dateend = $dateend; - $loan->nbterm = GETPOST("nbterm"); - $loan->rate = GETPOST("rate"); + $object->label = GETPOST("label"); + $object->fk_bank = GETPOST("accountid"); + $object->capital = GETPOST("capital"); + $object->datestart = $datestart; + $object->dateend = $dateend; + $object->nbterm = GETPOST("nbterm"); + $object->rate = GETPOST("rate"); - $loan->account_capital = GETPOST("accountancy_account_capital"); - $loan->account_insurance = GETPOST("accountancy_account_insurance"); - $loan->account_interest = GETPOST("accountancy_account_interest"); + $object->account_capital = GETPOST("accountancy_account_capital"); + $object->account_insurance = GETPOST("accountancy_account_insurance"); + $object->account_interest = GETPOST("accountancy_account_interest"); - $id=$loan->create($user); + $id=$object->create($user); if ($id <= 0) { - setEventMessage($loan->error, 'errors'); + setEventMessage($object->error, 'errors'); } } } -if ($action == 'update' && ! $_POST["cancel"] && $user->rights->loan->write) +if ($action == 'update' && ! $cancel && $user->rights->loan->write) { - $datestart=dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); - $dateend=dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); + $datestart=dol_mktime(12,0,0, $GETPOST("startmonth"), $GETPOST("startday"), $GETPOST("startyear")); + $dateend=dol_mktime(12,0,0, $GETPOST("endmonth"), $GETPOST("endday"), $GETPOST("endyear")); if (! $datestart) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); @@ -130,17 +131,22 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->loan->write) } else { - $loan = new Loan($db); - $result=$loan->fetch($_GET["id"]); - - $loan->label=$_POST["label"]; - $loan->datestart=$datestart; - $loan->dateend=$dateend; - - $result=$loan->update($user); - if ($result <= 0) + $object = new Loan($db); + if ($object->fetch($id)) { - setEventMessage($loan->error, 'errors'); + $object->label = $GETPOST("label"); + $object->datestart = $datestart; + $object->dateend = $dateend; + } + + if ($object->update($id, $user) > 0) + { + $action = ''; + } + else + { + $action = 'edit'; + setEventMessage($object->error, 'errors'); } } } @@ -180,7 +186,7 @@ if ($action == 'create') if (! empty($conf->banque->enabled)) { print ''.$langs->trans("Account").''; - $form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Show list of bank account with courant + $form->select_comptes($GETPOST["accountid"],"accountid",0,"courant=1",1); // Show list of bank account with courant print ''; } else @@ -259,7 +265,7 @@ if ($action == 'create') print ''; print '
    '; - print '
'; print ''; } @@ -434,8 +440,8 @@ if ($id > 0) print ""; /* - * Boutons actions - */ + * Buttons actions + */ if ($action != 'edit') { print "
\n"; @@ -474,7 +480,6 @@ if ($id > 0) } } - llxFooter(); -$db->close(); +$db->close(); \ No newline at end of file From dca4591cdf7615eb400c53dd21da5cf1a98c004c Mon Sep 17 00:00:00 2001 From: aspangaro Date: Thu, 2 Oct 2014 20:00:35 +0200 Subject: [PATCH 11/24] Add calculator --- htdocs/compta/loan/calculator.php | 223 ++++++++++++++++++++++++ htdocs/compta/loan/calculator.tpl | 150 ++++++++++++++++ htdocs/core/menus/standard/eldy.lib.php | 1 + htdocs/langs/en_US/loan.lang | 6 + htdocs/langs/fr_FR/loan.lang | 6 + 5 files changed, 386 insertions(+) create mode 100644 htdocs/compta/loan/calculator.php create mode 100644 htdocs/compta/loan/calculator.tpl diff --git a/htdocs/compta/loan/calculator.php b/htdocs/compta/loan/calculator.php new file mode 100644 index 00000000000..562ce2c27d5 --- /dev/null +++ b/htdocs/compta/loan/calculator.php @@ -0,0 +1,223 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/compta/loan/calculator.php + * \ingroup loan + * \brief Calculator for loan + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; + +$langs->load("loan"); +$langs->load("compta"); +$langs->load("banks"); +$langs->load("bills"); + +// Security check +$socid = isset($GETPOST["socid"])?$GETPOST["socid"]:''; +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'loan', '', '', ''); + +$action=GETPOST("action"); + +/* Defining Variables */ +$periods = array( + 52 => $langs->trans("Weekly"), + 26 => $langs->trans("Bi-weekly"), + 12 => $langs->trans("Monthly"), + 6 => $langs->trans("Bi-monthly"), + 4 => $langs->trans("Quarterly"), + 2 => $langs->trans("Semi-annually"), + 1 => $langs->trans("Annually") + ); + +$loan_capital = isset($GETPOST("loan_capital")) ? $GETPOST("loan_capital") : 0; +$loan_length = isset($GETPOST("loan_length")) ? $GETPOST("loan_length") : 0; +$loan_interest = isset(GETPOST("loan_interest")) ? $GETPOST("loan_interest") : 0; +$pay_periodicity = isset(GETPOST("pay_periodicity")) ? $GETPOST("pay_periodicity") : 12; +$periodicity = $periods[$pay_periodicity]; + +$pay_periods = ''; +foreach($periods as $value => $name) +{ + $selected = ($pay_periodicity == $value) ? 'selected' : ''; +} + +if ($action == 'calculate') +{ + /* Checking Variables */ + $error = 0; + + if(!is_numeric($loan_capital) || $loan_capital <= 0) + { + // $this->error="ErrorLoanCapital"; + return -1; + } + if(!is_numeric($loan_length) || $loan_length <= 0) + { + // $this->error="ErrorLoanLength"; + return -1; + } + if(!is_numeric($loan_interest) or $loan_interest <= 0) + { + // $this->error="ErrorLoanInterest"; + return -1; + } + + /* + * Calculating + */ + if(isset($_GET['action'])) + { + $c_balance = $loan_capital; + $total_periods = $loan_length * $pay_periodicity; + $interest_percent = $loan_interest / 100; + $period_interest = $interest_percent / $pay_periodicity; + $c_period_payment = $loan_capital * ($period_interest / (1 - pow((1 + $period_interest), -($total_periods)))); + $total_paid = number_format($c_period_payment * $total_periods, 2, '.', ' '); + $total_interest = number_format($c_period_payment * $total_periods - $loan_capital, 2, '.', ' '); + $total_principal = number_format($loan_capital, 2, '.', ' '); + + $loan_capital = number_format($loan_capital, 2, '.', ' '); + $loan_interest = number_format($loan_interest, 2, '.', ' '); + $period_payment = number_format($c_period_payment, 2, '.', ' '); + + for($period = 1; $period <= $total_periods; $period++) + { + $c_interest = $c_balance * $period_interest; + $c_principal = $c_period_payment - $c_interest; + $c_balance -= $c_principal; + + $interest = number_format($c_interest, 2, '.', ' '); + $principal = number_format($c_principal, 2, '.', ' '); + $balance = number_format($c_balance, 2, '.', ' '); + + $evenrow_row_modifier = ($period % 2) ? '' : 'class=evenrow'; + } + } + else + { + $amortization_table = ''; + $loan_summary = ''; + } +} + +/* + * View + */ + +$help_url='EN:Module_Loan|FR:Module_Emprunt'; +llxHeader("",$langs->trans("Loan"),$help_url); + +print_fiche_titre($langs->trans("CalculatorLoan")); + +print ''; + +print '' . "\n"; +print ''; +print ''; + +// Capital +print ''; + +// Length +print ''; + +// Interest +print ''; + +print '
'.$langs->trans("Capital").'
'.$langs->trans("LengthByYears").'
'.$langs->trans("Interest").' %
'; + +print '
'; + +print ''; + +if ($action == 'calculate') +{ +/* + + + + + + {amortization_table_rows} + + + +
PeriodInterest PaidPrincipal PaidRemaining Balance
Totals:{total_interest}${total_principal}$ 
+ + + + + {period} + {interest}$ + {principal}$ + {balance}$ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Loan Summary
Loan amount:{loan_amount}$
Loan length:{loan_length} years
Annual interest:{annual_interest}%
Pay periodicity:{periodicity}
{periodicity} payment:{period_payment}$
Total paid:{total_paid}$
Total interest:{total_interest}$
Total periods:{total_periods}
+ + */ +} +else +{ + +} + +$db->close(); + +llxFooter(); diff --git a/htdocs/compta/loan/calculator.tpl b/htdocs/compta/loan/calculator.tpl new file mode 100644 index 00000000000..7efbca9924b --- /dev/null +++ b/htdocs/compta/loan/calculator.tpl @@ -0,0 +1,150 @@ + + + + Loan Calculator + + + + + + + + + + +
+ {error} + + + + + +
+ {loan_summary} + {loan_parameters_form} + + {amortization_table} +
+
+ + + +
+ + + + + + + + + + +
Loan Parameters
+ + + + + + + + + + + + + + + + + + + + +
Loan amount: $
Loan length: years
Annual interest: %
Pay periodicity: + +
+
Powered by PC Calculators
+
+ + + + + + + + + + + + {amortization_table_rows} + + + +
PeriodInterest PaidPrincipal PaidRemaining Balance
Totals:{total_interest}${total_principal}$ 
+ + + + + {period} + {interest}$ + {principal}$ + {balance}$ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Loan Summary
Loan amount:{loan_amount}$
Loan length:{loan_length} years
Annual interest:{annual_interest}%
Pay periodicity:{periodicity}
{periodicity} payment:{period_payment}$
Total paid:{total_paid}$
Total interest:{total_interest}$
Total periods:{total_periods}
+ + + + + + diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index c3df5b82fff..bea92481d12 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -825,6 +825,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy",$langs->trans("Loans"),1,$user->rights->loan->read, '', $mainmenu, 'tax_loan'); if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/card.php?leftmenu=tax_loan&action=create",$langs->trans("NewLoan"),2,$user->rights->loan->write); if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read); + if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/calculator.php?leftmenu=tax_loan",$langs->trans("Calculator"),2,$user->rights->loan->read); } // Social contributions diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang index 6be2f13a101..37523b7408b 100644 --- a/htdocs/langs/en_US/loan.lang +++ b/htdocs/langs/en_US/loan.lang @@ -9,6 +9,12 @@ Nbterms=Number of terms LoanAccountancyCapitalCode=Accountancy code capital LoanAccountancyInsuranceCode=Accountancy code insurance LoanAccountancyInterestCode=Accountancy code interest +Calculator=Simulator +CalculatorLoan=Loan simulator +ErrorLoanCapital=Loan amount has to be numeric and greater than zero. +ErrorLoanLength=Loan length has to be numeric and greater than zero. +ErrorLoanInterest=Annual interest has to be numeric and greater than zero. +# Admin ConfigLoan=Configuration of the module loan LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Accountancy code capital by default LOAN_ACCOUNTING_ACCOUNT_INTEREST=Accountancy code interest by default diff --git a/htdocs/langs/fr_FR/loan.lang b/htdocs/langs/fr_FR/loan.lang index d230f7f0582..c699388e0c0 100644 --- a/htdocs/langs/fr_FR/loan.lang +++ b/htdocs/langs/fr_FR/loan.lang @@ -9,6 +9,12 @@ Nbterms=Nombre d'échéances LoanAccountancyCapitalCode=Compte comptable capital LoanAccountancyInsuranceCode=Compte comptable assurance LoanAccountancyInterestCode=Compte comptable intérêts +Calculator=Simulateur +CalculatorLoan=Simulateur d'emprunt +ErrorLoanCapital=Le capital de l'emprunt doit être au format numérique et supérieur à zéro. +ErrorLoanLength=La durée de l'emprunt doit être au format numérique et supérieur à zéro. +ErrorLoanInterest=Les intérêts d'emprunt doivent être au format numérique et supérieur à zéro. +# Admin ConfigLoan=Configuration du module emprunt LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Compte comptable capital par défaut LOAN_ACCOUNTING_ACCOUNT_INTEREST=Compte comptable intérêts par défaut From 7fa2b6b3ebea20771d330ed97a5c339d2cdf2e2a Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 6 Oct 2014 05:34:45 +0200 Subject: [PATCH 12/24] Update --- htdocs/compta/loan/calculator.php | 223 ------------------------ htdocs/compta/loan/calculator.tpl | 150 ---------------- htdocs/compta/loan/card.php | 2 +- htdocs/core/menus/standard/eldy.lib.php | 1 - htdocs/langs/en_US/loan.lang | 4 +- htdocs/langs/fr_FR/loan.lang | 4 +- 6 files changed, 5 insertions(+), 379 deletions(-) delete mode 100644 htdocs/compta/loan/calculator.php delete mode 100644 htdocs/compta/loan/calculator.tpl diff --git a/htdocs/compta/loan/calculator.php b/htdocs/compta/loan/calculator.php deleted file mode 100644 index 562ce2c27d5..00000000000 --- a/htdocs/compta/loan/calculator.php +++ /dev/null @@ -1,223 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/compta/loan/calculator.php - * \ingroup loan - * \brief Calculator for loan - */ - -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; - -$langs->load("loan"); -$langs->load("compta"); -$langs->load("banks"); -$langs->load("bills"); - -// Security check -$socid = isset($GETPOST["socid"])?$GETPOST["socid"]:''; -if ($user->societe_id) $socid=$user->societe_id; -$result = restrictedArea($user, 'loan', '', '', ''); - -$action=GETPOST("action"); - -/* Defining Variables */ -$periods = array( - 52 => $langs->trans("Weekly"), - 26 => $langs->trans("Bi-weekly"), - 12 => $langs->trans("Monthly"), - 6 => $langs->trans("Bi-monthly"), - 4 => $langs->trans("Quarterly"), - 2 => $langs->trans("Semi-annually"), - 1 => $langs->trans("Annually") - ); - -$loan_capital = isset($GETPOST("loan_capital")) ? $GETPOST("loan_capital") : 0; -$loan_length = isset($GETPOST("loan_length")) ? $GETPOST("loan_length") : 0; -$loan_interest = isset(GETPOST("loan_interest")) ? $GETPOST("loan_interest") : 0; -$pay_periodicity = isset(GETPOST("pay_periodicity")) ? $GETPOST("pay_periodicity") : 12; -$periodicity = $periods[$pay_periodicity]; - -$pay_periods = ''; -foreach($periods as $value => $name) -{ - $selected = ($pay_periodicity == $value) ? 'selected' : ''; -} - -if ($action == 'calculate') -{ - /* Checking Variables */ - $error = 0; - - if(!is_numeric($loan_capital) || $loan_capital <= 0) - { - // $this->error="ErrorLoanCapital"; - return -1; - } - if(!is_numeric($loan_length) || $loan_length <= 0) - { - // $this->error="ErrorLoanLength"; - return -1; - } - if(!is_numeric($loan_interest) or $loan_interest <= 0) - { - // $this->error="ErrorLoanInterest"; - return -1; - } - - /* - * Calculating - */ - if(isset($_GET['action'])) - { - $c_balance = $loan_capital; - $total_periods = $loan_length * $pay_periodicity; - $interest_percent = $loan_interest / 100; - $period_interest = $interest_percent / $pay_periodicity; - $c_period_payment = $loan_capital * ($period_interest / (1 - pow((1 + $period_interest), -($total_periods)))); - $total_paid = number_format($c_period_payment * $total_periods, 2, '.', ' '); - $total_interest = number_format($c_period_payment * $total_periods - $loan_capital, 2, '.', ' '); - $total_principal = number_format($loan_capital, 2, '.', ' '); - - $loan_capital = number_format($loan_capital, 2, '.', ' '); - $loan_interest = number_format($loan_interest, 2, '.', ' '); - $period_payment = number_format($c_period_payment, 2, '.', ' '); - - for($period = 1; $period <= $total_periods; $period++) - { - $c_interest = $c_balance * $period_interest; - $c_principal = $c_period_payment - $c_interest; - $c_balance -= $c_principal; - - $interest = number_format($c_interest, 2, '.', ' '); - $principal = number_format($c_principal, 2, '.', ' '); - $balance = number_format($c_balance, 2, '.', ' '); - - $evenrow_row_modifier = ($period % 2) ? '' : 'class=evenrow'; - } - } - else - { - $amortization_table = ''; - $loan_summary = ''; - } -} - -/* - * View - */ - -$help_url='EN:Module_Loan|FR:Module_Emprunt'; -llxHeader("",$langs->trans("Loan"),$help_url); - -print_fiche_titre($langs->trans("CalculatorLoan")); - -print ''; - -print '' . "\n"; -print ''; -print ''; - -// Capital -print ''; - -// Length -print ''; - -// Interest -print ''; - -print '
'.$langs->trans("Capital").'
'.$langs->trans("LengthByYears").'
'.$langs->trans("Interest").' %
'; - -print '
'; - -print ''; - -if ($action == 'calculate') -{ -/* - - - - - - {amortization_table_rows} - - - -
PeriodInterest PaidPrincipal PaidRemaining Balance
Totals:{total_interest}${total_principal}$ 
- - - - - {period} - {interest}$ - {principal}$ - {balance}$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Loan Summary
Loan amount:{loan_amount}$
Loan length:{loan_length} years
Annual interest:{annual_interest}%
Pay periodicity:{periodicity}
{periodicity} payment:{period_payment}$
Total paid:{total_paid}$
Total interest:{total_interest}$
Total periods:{total_periods}
- - */ -} -else -{ - -} - -$db->close(); - -llxFooter(); diff --git a/htdocs/compta/loan/calculator.tpl b/htdocs/compta/loan/calculator.tpl deleted file mode 100644 index 7efbca9924b..00000000000 --- a/htdocs/compta/loan/calculator.tpl +++ /dev/null @@ -1,150 +0,0 @@ - - - - Loan Calculator - - - - - - - - - - -
- {error} - - - - - -
- {loan_summary} - {loan_parameters_form} - - {amortization_table} -
-
- - - -
- - - - - - - - - - -
Loan Parameters
- - - - - - - - - - - - - - - - - - - - -
Loan amount: $
Loan length: years
Annual interest: %
Pay periodicity: - -
-
Powered by PC Calculators
-
- - - - - - - - - - - - {amortization_table_rows} - - - -
PeriodInterest PaidPrincipal PaidRemaining Balance
Totals:{total_interest}${total_principal}$ 
- - - - - {period} - {interest}$ - {principal}$ - {balance}$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Loan Summary
Loan amount:{loan_amount}$
Loan length:{loan_length} years
Annual interest:{annual_interest}%
Pay periodicity:{periodicity}
{periodicity} payment:{period_payment}$
Total paid:{total_paid}$
Total interest:{total_interest}$
Total periods:{total_periods}
- - - - - - diff --git a/htdocs/compta/loan/card.php b/htdocs/compta/loan/card.php index c97ca6d84b0..e49aee1b61f 100644 --- a/htdocs/compta/loan/card.php +++ b/htdocs/compta/loan/card.php @@ -297,7 +297,7 @@ if ($id > 0) if ($action == 'edit') { - print "
id&action=update\" method=\"post\">"; + print 'id&action=update" method="POST">'; print ''; } diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 86e74cfcc5f..1e4f1197cb0 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -834,7 +834,6 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy",$langs->trans("Loans"),1,$user->rights->loan->read, '', $mainmenu, 'tax_loan'); if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/card.php?leftmenu=tax_loan&action=create",$langs->trans("NewLoan"),2,$user->rights->loan->write); if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read); - if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/calculator.php?leftmenu=tax_loan",$langs->trans("Calculator"),2,$user->rights->loan->read); } // Social contributions diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang index 37523b7408b..10fb0249f6d 100644 --- a/htdocs/langs/en_US/loan.lang +++ b/htdocs/langs/en_US/loan.lang @@ -9,8 +9,8 @@ Nbterms=Number of terms LoanAccountancyCapitalCode=Accountancy code capital LoanAccountancyInsuranceCode=Accountancy code insurance LoanAccountancyInterestCode=Accountancy code interest -Calculator=Simulator -CalculatorLoan=Loan simulator +ConfirmDeleteLoan=Confirm deleting this loan +ConfirmPayLoan=Confirm classify paid this loan ErrorLoanCapital=Loan amount has to be numeric and greater than zero. ErrorLoanLength=Loan length has to be numeric and greater than zero. ErrorLoanInterest=Annual interest has to be numeric and greater than zero. diff --git a/htdocs/langs/fr_FR/loan.lang b/htdocs/langs/fr_FR/loan.lang index c699388e0c0..1e54f90e2be 100644 --- a/htdocs/langs/fr_FR/loan.lang +++ b/htdocs/langs/fr_FR/loan.lang @@ -9,8 +9,8 @@ Nbterms=Nombre d'échéances LoanAccountancyCapitalCode=Compte comptable capital LoanAccountancyInsuranceCode=Compte comptable assurance LoanAccountancyInterestCode=Compte comptable intérêts -Calculator=Simulateur -CalculatorLoan=Simulateur d'emprunt +ConfirmDeleteLoan=Confirmation de supression de cet emprunt +ConfirmPayLoan=Confirmation que cet emprunt est classé comme payé ErrorLoanCapital=Le capital de l'emprunt doit être au format numérique et supérieur à zéro. ErrorLoanLength=La durée de l'emprunt doit être au format numérique et supérieur à zéro. ErrorLoanInterest=Les intérêts d'emprunt doivent être au format numérique et supérieur à zéro. From aecb9856593d36d2226a6e952d51c433a052f1d9 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Tue, 4 Nov 2014 20:53:07 +0100 Subject: [PATCH 13/24] Update work --- htdocs/compta/loan/card.php | 28 ++++++++++++++-------------- htdocs/compta/loan/index.php | 23 +++++++++++++++++------ htdocs/compta/salaries/card.php | 2 +- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/htdocs/compta/loan/card.php b/htdocs/compta/loan/card.php index e49aee1b61f..49e3884562c 100644 --- a/htdocs/compta/loan/card.php +++ b/htdocs/compta/loan/card.php @@ -69,12 +69,12 @@ if ($action == 'confirm_delete' && $confirm == 'yes') } } - // Add loan if ($action == 'add' && $user->rights->loan->write) { - $datestart=dol_mktime(12,0,0, $GETPOST("startmonth"), $GETPOST("startday"), $GETPOST("startyear")); - $dateend=dol_mktime(12,0,0, $GETPOST("endmonth"), $GETPOST("endday"), $GETPOST("endyear")); + $datestart=@dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); + $dateend=@dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); + if (! $datestart) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); @@ -94,17 +94,17 @@ if ($action == 'add' && $user->rights->loan->write) { $object = new Loan($db); - $object->label = GETPOST("label"); - $object->fk_bank = GETPOST("accountid"); - $object->capital = GETPOST("capital"); - $object->datestart = $datestart; - $object->dateend = $dateend; - $object->nbterm = GETPOST("nbterm"); - $object->rate = GETPOST("rate"); + $object->label = $_POST["label"]; + $object->fk_bank = $_POST["accountid"]; + $object->capital = $_POST["capital"]; + $object->datestart = $datestart; + $object->dateend = $dateend; + $object->nbterm = $_POST["nbterm"]; + $object->rate = $_POST["rate"]; - $object->account_capital = GETPOST("accountancy_account_capital"); - $object->account_insurance = GETPOST("accountancy_account_insurance"); - $object->account_interest = GETPOST("accountancy_account_interest"); + $object->account_capital = $_POST["accountancy_account_capital"]; + $object->account_insurance = $_POST["accountancy_account_insurance"]; + $object->account_interest = $_POST["accountancy_account_interest"]; $id=$object->create($user); if ($id <= 0) @@ -173,7 +173,7 @@ if ($action == 'create') $datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int')); - print '' . "\n"; + print '' . "\n"; print ''; print ''; diff --git a/htdocs/compta/loan/index.php b/htdocs/compta/loan/index.php index a4432ba9ced..2834ce2069f 100644 --- a/htdocs/compta/loan/index.php +++ b/htdocs/compta/loan/index.php @@ -45,8 +45,16 @@ if (! $sortfield) $sortfield="l.rowid"; if (! $sortorder) $sortorder="DESC"; $limit = $conf->liste_limit; +$search_ref=GETPOST('search_ref','int'); $search_label=GETPOST('search_label','alpha'); -$filtre=$_GET["filtre"]; +$filtre=GETPOST("filtre"); + +if (GETPOST("button_removefilter")) +{ + $search_ref=""; + $search_label=""; + $search_amount=""; +} /* * View @@ -56,13 +64,14 @@ $loan = new Loan($db); llxHeader(); -$sql = "SELECT l.rowid as id, l.label, l.capital, l.datestart, l.dateend,"; +$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend,"; $sql.= " SUM(pl.amount) as alreadypayed"; $sql.= " FROM ".MAIN_DB_PREFIX."loan as l,"; $sql.= " ".MAIN_DB_PREFIX."payment_loan as pl"; $sql.= " WHERE pl.fk_loan = l.rowid"; $sql.= " AND l.entity = ".$conf->entity; -if (GETPOST("search_label")) $sql.=" AND l.label LIKE '%".$db->escape(GETPOST("search_label"))."%'"; +if (GETPOST("search_ref")) $sql.=" AND (l.rowid = ".$db->escape($search_ref).")"; +if (GETPOST("search_label")) $sql.=" AND l.label LIKE '%".$db->escape($search_label)."%'"; if ($filtre) { $filtre=str_replace(":","=",$filtre); @@ -83,7 +92,7 @@ if ($resql) print ''."\n"; print ''; print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"id","",$param,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"l.rowid","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"l.label","",$param,'align="left"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Capital"),$_SERVER["PHP_SELF"],"l.capital","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"l.datestart","",$param,'align="center"',$sortfield,$sortorder); @@ -96,9 +105,11 @@ if ($resql) print ''; print ''; print ''; - print '\n"; + print ''; + print ''; + print ''; $var=true; while ($i < min($num,$limit)) diff --git a/htdocs/compta/salaries/card.php b/htdocs/compta/salaries/card.php index 3ee796c6134..c6e492cd787 100644 --- a/htdocs/compta/salaries/card.php +++ b/htdocs/compta/salaries/card.php @@ -206,7 +206,7 @@ if ($action == 'create') $datesp=dol_get_first_day($pastmonthyear,$pastmonth,false); $dateep=dol_get_last_day($pastmonthyear,$pastmonth,false); } - print "\n"; + print ''; print ''; print ''; From 3042bf4dc2a4fbaab5d759fcf94a2b809b1de2a8 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 10 Nov 2014 06:08:50 +0100 Subject: [PATCH 14/24] Correct lot of bugs --- htdocs/compta/loan/card.php | 176 +++++++++--------- htdocs/compta/loan/class/loan.class.php | 82 ++++---- .../compta/loan/class/paymentloan.class.php | 29 ++- htdocs/compta/loan/index.php | 42 ++--- htdocs/compta/loan/payment/card.php | 19 +- htdocs/compta/loan/payment/payment.php | 74 +++++--- .../install/mysql/migration/3.6.0-3.7.0.sql | 42 ----- .../install/mysql/migration/3.7.0-3.8.0.sql | 63 +++++++ .../install/mysql/tables/llx_payment_loan.sql | 4 +- htdocs/langs/en_US/loan.lang | 3 + htdocs/langs/fr_FR/loan.lang | 3 + 11 files changed, 306 insertions(+), 231 deletions(-) create mode 100644 htdocs/install/mysql/migration/3.7.0-3.8.0.sql diff --git a/htdocs/compta/loan/card.php b/htdocs/compta/loan/card.php index 49e3884562c..88a4429e7c5 100644 --- a/htdocs/compta/loan/card.php +++ b/htdocs/compta/loan/card.php @@ -33,13 +33,15 @@ $langs->load("loan"); $id=GETPOST('id','int'); $action=GETPOST('action'); $confirm=GETPOST('confirm'); -$cancel=GETPOST('cancel'); +$cancel=GETPOST('cancel','alpha'); // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'loan', $id, '',''); +$object = new Loan($db); + /* * Actions */ @@ -47,7 +49,6 @@ $result = restrictedArea($user, 'loan', $id, '',''); // Classify paid if ($action == 'confirm_paid' && $confirm == 'yes') { - $object = new Loan($db); $object->fetch($id); $result = $object->set_paid($user); } @@ -55,7 +56,6 @@ if ($action == 'confirm_paid' && $confirm == 'yes') // Delete loan if ($action == 'confirm_delete' && $confirm == 'yes') { - $object = new Loan($db); $object->fetch($id); $result=$object->delete($user); if ($result > 0) @@ -72,86 +72,88 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // Add loan if ($action == 'add' && $user->rights->loan->write) { - $datestart=@dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); - $dateend=@dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); - - if (! $datestart) + if (! $cancel) { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); - $action = 'create'; - } - elseif (! $dateend) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors'); - $action = 'create'; - } - elseif (! $_POST["capital"]) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Capital")), 'errors'); - $action = 'create'; - } - else - { - $object = new Loan($db); - - $object->label = $_POST["label"]; - $object->fk_bank = $_POST["accountid"]; - $object->capital = $_POST["capital"]; - $object->datestart = $datestart; - $object->dateend = $dateend; - $object->nbterm = $_POST["nbterm"]; - $object->rate = $_POST["rate"]; + $datestart=@dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); + $dateend=@dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); - $object->account_capital = $_POST["accountancy_account_capital"]; - $object->account_insurance = $_POST["accountancy_account_insurance"]; - $object->account_interest = $_POST["accountancy_account_interest"]; - - $id=$object->create($user); - if ($id <= 0) + if (! $datestart) { - setEventMessage($object->error, 'errors'); + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); + $action = 'create'; } - } -} - - -if ($action == 'update' && ! $cancel && $user->rights->loan->write) -{ - $datestart=dol_mktime(12,0,0, $GETPOST("startmonth"), $GETPOST("startday"), $GETPOST("startyear")); - $dateend=dol_mktime(12,0,0, $GETPOST("endmonth"), $GETPOST("endday"), $GETPOST("endyear")); - if (! $datestart) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); - $action = 'edit'; - } - elseif (! $dateend) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors'); - $action = 'edit'; - } - else - { - $object = new Loan($db); - if ($object->fetch($id)) + elseif (! $dateend) { - $object->label = $GETPOST("label"); - $object->datestart = $datestart; - $object->dateend = $dateend; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors'); + $action = 'create'; } - - if ($object->update($id, $user) > 0) + elseif (! $_POST["capital"]) { - $action = ''; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Capital")), 'errors'); + $action = 'create'; } else { - $action = 'edit'; - setEventMessage($object->error, 'errors'); + $object->label = $_POST["label"]; + $object->fk_bank = $_POST["accountid"]; + $object->capital = $_POST["capital"]; + $object->datestart = $datestart; + $object->dateend = $dateend; + $object->nbterm = $_POST["nbterm"]; + $object->rate = $_POST["rate"]; + + $object->account_capital = $_POST["accountancy_account_capital"]; + $object->account_insurance = $_POST["accountancy_account_insurance"]; + $object->account_interest = $_POST["accountancy_account_interest"]; + + $id=$object->create($user); + if ($id <= 0) + { + setEventMessage($object->error, 'errors'); + } } } + else + { + header("Location: index.php"); + exit(); + } } +// Update record +else if ($action == 'update' && $user->rights->loan->write) +{ + if (! $cancel) + { + $result = $object->fetch($id); + + if ($object->fetch($id)) + { + $object->label = GETPOST("label"); + $object->datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int')); + $object->dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int')); + $object->nbterm = GETPOST("nbterm"); + $object->rate = GETPOST("rate"); + } + + $result = $object->update($user); + if ($result > 0) + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } + else + { + setEventMessage($object->error, 'errors'); + } + } + else + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } +} /* * View @@ -212,10 +214,10 @@ if ($action == 'create') print ''; // Number of terms - print ''; + print ''; // Rate - print ''; + print ''; // Note print ''; @@ -273,7 +275,6 @@ if ($action == 'create') // View if ($id > 0) { - $object = new Loan($db); $result = $object->fetch($id); if ($result > 0) @@ -297,8 +298,10 @@ if ($id > 0) if ($action == 'edit') { - print 'id&action=update" method="POST">'; - print ''; + print '' . "\n"; + print ''; + print ''; + print ''; } print '
  '; + print ''; print ''; - print "
'.$langs->trans("Nbterms").'
'.$langs->trans("Nbterms").'
'.$langs->trans("Rate").'
'.$langs->trans("Rate").' %
'; @@ -353,7 +356,7 @@ if ($id > 0) print ''; // Rate - print ''; + print ''; // Status print ''; @@ -378,8 +381,9 @@ if ($id > 0) /* * Payments */ - $sql = "SELECT p.rowid, p.num_payment, datep as dp, p.amount,"; - $sql.= "c.libelle as paiement_type"; + $sql = "SELECT p.rowid, p.num_payment, datep as dp,"; + $sql.= " p.amount_capital, p.amount_insurance, p.amount_interest,"; + $sql.= " c.libelle as paiement_type"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; $sql.= ", ".MAIN_DB_PREFIX."loan as l"; @@ -400,7 +404,9 @@ if ($id > 0) print ''; print ''; print ''; - print ''; + print ''; + print ''; + print ''; print ''; print ''; @@ -413,21 +419,23 @@ if ($id > 0) print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''; print '\n"; print "\n"; - print '\n"; + print '\n"; + print '\n"; + print '\n"; print ""; - $totalpaid += $objp->amount; + $totalpaid += $objp->amount_capital; $i++; } if ($object->paid == 0) { - print "\n"; - print "\n"; + print ''; + print ''; $staytopay = $object->capital - $totalpaid; - print ""; - print "\n"; + print ''; + print ''; } print "
'.$langs->trans("Nbterms").''.$object->nbterm.'
'.$langs->trans("Rate").''.$object->rate.'
'.$langs->trans("Rate").''.$object->rate.' %
'.$langs->trans("Status").''.$object->getLibStatut(4, $totalpaye).'
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").''.$langs->trans("Insurance").''.$langs->trans("Interest").''.$langs->trans("Capital").' 
'.dol_print_date($db->jdate($objp->dp),'day')."".$objp->paiement_type.' '.$objp->num_payment."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."'.price($objp->amount_insurance)." ".$langs->trans("Currency".$conf->currency)."'.price($objp->amount_interest)." ".$langs->trans("Currency".$conf->currency)."'.price($objp->amount_capital)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaid)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->capital)." ".$langs->trans("Currency".$conf->currency)."
'.$langs->trans("AlreadyPaid").' :'.price($totalpaid).' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("AmountExpected").' :'.price($object->capital).' '.$langs->trans("Currency".$conf->currency).'
".$langs->trans("RemainderToPay")." :".price($staytopay)." ".$langs->trans("Currency".$conf->currency)."
'.$langs->trans("RemainderToPay").' :'.price($staytopay).' '.$langs->trans("Currency".$conf->currency).'
"; $db->free($resql); @@ -444,7 +452,7 @@ if ($id > 0) */ if ($action != 'edit') { - print "
\n"; + print '
'; // Edit if ($user->rights->loan->write) diff --git a/htdocs/compta/loan/class/loan.class.php b/htdocs/compta/loan/class/loan.class.php index 07b842b708e..b8fcf04728f 100644 --- a/htdocs/compta/loan/class/loan.class.php +++ b/htdocs/compta/loan/class/loan.class.php @@ -263,8 +263,8 @@ class Loan extends CommonObject /** * Update loan * - * @param User $user Utilisateur qui modifie - * @return int <0 si erreur, >0 si ok + * @param User $user User who modified + * @return int <0 if error, >0 if ok */ function update($user) { @@ -273,7 +273,8 @@ class Loan extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."loan"; $sql.= " SET label='".$this->db->escape($this->label)."',"; $sql.= " datestart='".$this->db->idate($this->datestart)."',"; - $sql.= " dateend='".$this->db->idate($this->dateend)."'"; + $sql.= " dateend='".$this->db->idate($this->dateend)."',"; + $sql.= " fk_user_modif = ".$user->id; $sql.= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::update", LOG_DEBUG); @@ -379,7 +380,7 @@ class Loan extends CommonObject * @param int $maxlen Label max length * @return string Chaine with URL */ - function getNameUrl($withpicto=0,$maxlen=0) + function getLinkUrl($withpicto=0,$maxlen=0) { global $langs; @@ -432,40 +433,43 @@ class Loan extends CommonObject * @param int $id Id of record * @return void */ - function info($id) - { - $sql = "SELECT l.rowid, l.tms as datem, l.fk_user_author as user_author, l.datec as datec"; - $sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; - $sql.= " WHERE l.rowid = ".$id; + function info($id) + { + $sql = 'SELECT l.rowid, l.datec, l.fk_user_author, l.fk_user_modif,'; + $sql.= ' l.tms'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'loan as l'; + $sql.= ' WHERE l.rowid = '.$id; - dol_syslog(get_class($this)."::info", LOG_DEBUG); - $result=$this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - - if ($obj->user_author) { - $cuser = new User($this->db); - $cuser->fetch($obj->user_author); - $this->user_creation = $cuser; - } - - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_modification = $this->db->jdate($obj->datem); - - } - - $this->db->free($result); - - } - else - { - dol_print_error($this->db); - } - } -} + dol_syslog(get_class($this).'::info', LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $this->id = $obj->rowid; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + if ($obj->fk_user_modif) + { + $muser = new User($this->db); + $muser->fetch($obj->fk_user_modif); + $this->user_modification = $muser; + } + $this->date_creation = $this->db->jdate($obj->datec); + if (empty($obj->fk_user_modif)) $obj->tms = ""; + $this->date_modification = $this->db->jdate($obj->tms); + } + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + } +} \ No newline at end of file diff --git a/htdocs/compta/loan/class/paymentloan.class.php b/htdocs/compta/loan/class/paymentloan.class.php index 0a558fc9bf4..944cfe4ce2f 100644 --- a/htdocs/compta/loan/class/paymentloan.class.php +++ b/htdocs/compta/loan/class/paymentloan.class.php @@ -39,8 +39,10 @@ class PaymentLoan extends CommonObject var $datec=''; var $tms=''; var $datep=''; - var $amount; // Total amount of payment var $amounts=array(); // Array of amounts + var $amount_capital; // Total amount of payment + var $amount_insurance; + var $amount_interest; var $fk_typepayment; var $num_payment; var $note; @@ -82,7 +84,9 @@ class PaymentLoan extends CommonObject // Clean parameters if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan); - if (isset($this->amount)) $this->amount = trim($this->amount); + if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital); + if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance); + if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest); if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); if (isset($this->note)) $this->note = trim($this->note); @@ -107,7 +111,7 @@ class PaymentLoan extends CommonObject if ($totalamount != 0) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan (fk_loan, datec, datep, amount,"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,"; $sql.= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)"; $sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',"; $sql.= " '".$this->db->idate($this->datepaid)."',"; @@ -130,7 +134,7 @@ class PaymentLoan extends CommonObject if ($totalamount != 0 && ! $error) { - $this->amount=$totalamount; + $this->amount_capital=$totalamount; $this->total=$totalamount; // deprecated $this->db->commit(); return $this->id; @@ -158,7 +162,9 @@ class PaymentLoan extends CommonObject $sql.= " t.datec,"; $sql.= " t.tms,"; $sql.= " t.datep,"; - $sql.= " t.amount,"; + $sql.= " t.amount_capital,"; + $sql.= " t.amount_insurance,"; + $sql.= " t.amount_interest,"; $sql.= " t.fk_typepayment,"; $sql.= " t.num_payment,"; $sql.= " t.note,"; @@ -186,7 +192,9 @@ class PaymentLoan extends CommonObject $this->datec = $this->db->jdate($obj->datec); $this->tms = $this->db->jdate($obj->tms); $this->datep = $this->db->jdate($obj->datep); - $this->amount = $obj->amount; + $this->amount_capital = $obj->amount_capital; + $this->amount_insurance = $obj->amount_insurance; + $this->amount_interest = $obj->amount_interest; $this->fk_typepayment = $obj->fk_typepayment; $this->num_payment = $obj->num_payment; $this->note = $obj->note; @@ -225,9 +233,10 @@ class PaymentLoan extends CommonObject $error=0; // Clean parameters - if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan); - if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->amount_capital)) $this->amount_capital=trim($this->amount_capital); + if (isset($this->amount_insurance)) $this->amount_insurance=trim($this->amount_insurance); + if (isset($this->amount_interest)) $this->amount_interest=trim($this->amount_interest); if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); if (isset($this->note)) $this->note=trim($this->note); @@ -245,7 +254,9 @@ class PaymentLoan extends CommonObject $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; - $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; + $sql.= " amount_capital=".(isset($this->amount_capital)?$this->amount_capital:"null").","; + $sql.= " amount_insurance=".(isset($this->amount_insurance)?$this->amount_insurance:"null").","; + $sql.= " amount_interest=".(isset($this->amount_interest)?$this->amount_interest:"null").","; $sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").","; $sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").","; $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").","; diff --git a/htdocs/compta/loan/index.php b/htdocs/compta/loan/index.php index 2834ce2069f..720b52de0a1 100644 --- a/htdocs/compta/loan/index.php +++ b/htdocs/compta/loan/index.php @@ -47,6 +47,7 @@ $limit = $conf->liste_limit; $search_ref=GETPOST('search_ref','int'); $search_label=GETPOST('search_label','alpha'); +$search_amount=GETPOST('search_amount','alpha'); $filtre=GETPOST("filtre"); if (GETPOST("button_removefilter")) @@ -60,36 +61,37 @@ if (GETPOST("button_removefilter")) * View */ -$loan = new Loan($db); +$loan_static = new Loan($db); llxHeader(); $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend,"; -$sql.= " SUM(pl.amount) as alreadypayed"; -$sql.= " FROM ".MAIN_DB_PREFIX."loan as l,"; -$sql.= " ".MAIN_DB_PREFIX."payment_loan as pl"; -$sql.= " WHERE pl.fk_loan = l.rowid"; -$sql.= " AND l.entity = ".$conf->entity; -if (GETPOST("search_ref")) $sql.=" AND (l.rowid = ".$db->escape($search_ref).")"; -if (GETPOST("search_label")) $sql.=" AND l.label LIKE '%".$db->escape($search_label)."%'"; - +$sql.= " SUM(pl.amount_capital) as alreadypayed"; +$sql.= " FROM ".MAIN_DB_PREFIX."loan as l LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl"; +$sql.= " ON l.rowid = pl.fk_loan"; +$sql.= " WHERE l.entity = ".$conf->entity; +if ($search_amount) $sql.=" AND l.capital='".$db->escape(price2num(trim($search_amount)))."'"; +if ($search_ref) $sql.=" AND l.rowid = ".$db->escape($search_ref); +if ($search_label) $sql.=" AND l.label LIKE '%".$db->escape($search_label)."%'"; if ($filtre) { $filtre=str_replace(":","=",$filtre); $sql .= " AND ".$filtre; } +$sql.= " GROUP BY l.rowid, l.label, l.capital, l.datestart, l.dateend"; $sql.= $db->order($sortfield,$sortorder); -$sql.= $db->plimit($limit + 1, $offset); +$sql.= $db->plimit($limit+1, $offset); //print $sql; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); + $i = 0; + $var=true; print_fiche_titre($langs->trans("Loans")); - $i = 0; - print ''."\n"; + print ''."\n"; print ''; print ''; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"l.rowid","",$param,"",$sortfield,$sortorder); @@ -101,9 +103,9 @@ if ($resql) // Filters lines print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; print ''; print ''; print ''; - $var=true; while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); - + $var = !$var; print ""; // Ref - print ''; + print ''; // Label print ''; @@ -134,7 +132,7 @@ if ($resql) // Date start print ''; - print ''; + print ''; print "\n"; diff --git a/htdocs/compta/loan/payment/card.php b/htdocs/compta/loan/payment/card.php index d08c5f8ce0f..4dc1407e8ad 100644 --- a/htdocs/compta/loan/payment/card.php +++ b/htdocs/compta/loan/payment/card.php @@ -118,7 +118,6 @@ if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->loan->wri llxHeader(); $loan = new Loan($db); - $form = new Form($db); $h=0; @@ -168,7 +167,9 @@ print ''; // Amount -print ''; +print ''; +print ''; +print ''; // Note print ''; @@ -198,7 +199,7 @@ print '
   '; print ''; @@ -111,19 +113,15 @@ if ($resql) print '
'; - $loan->id = $obj->id; - print $loan->getNameUrl(1,'20'); - print ''.img_object($langs->trans("ShowLoan"),"label").' '.$obj->rowid.''.dol_trunc($obj->label,42).''.dol_print_date($db->jdate($obj->datestart), 'day').''.$loan->LibStatut($obj->paid,5,$obj->alreadypayed).''.$loan_static->LibStatut($obj->paid,5,$obj->alreadypayed).'
'.$langs->trans('Mode').''.$lan print '
'.$langs->trans('Number').''.$payment->num_payment.'
'.$langs->trans('Amount').''.price($payment->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Capital').''.price($payment->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Insurance').''.price($payment->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Interest').''.price($payment->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Note').''.nl2br($payment->note).'
'; */ $disable_delete = 0; -$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount'; +$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest'; $sql.= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l'; $sql.= ' WHERE pl.fk_loan = l.rowid'; $sql.= ' AND l.entity = '.$conf->entity; @@ -234,22 +235,22 @@ if ($resql) // Ref print ''; $loan->fetch($objp->id); - print $loan->getNameUrl(1); + print $loan->getLinkUrl(1); print "\n"; // Label print ''.$objp->label.''; // Expected to pay print ''.price($objp->capital).''; // Status - print ''.$loan->getLibStatut(4,$objp->amount).''; + print ''.$loan->getLibStatut(4,$objp->amount_capital).''; // Amount payed - print ''.price($objp->amount).''; + print ''.price($objp->amount_capital).''; print "\n"; - if ($objp->paye == 1) // If at least one invoice is paid, disable delete + if ($objp->paid == 1) // If at least one invoice is paid, disable delete { $disable_delete = 1; } - $total = $total + $objp->amount; + $total = $total + $objp->amount_capital; $i++; } } @@ -267,7 +268,7 @@ print '
'; /* - * Boutons Actions + * Actions buttons */ print '
'; diff --git a/htdocs/compta/loan/payment/payment.php b/htdocs/compta/loan/payment/payment.php index ed249d8f246..678ca1b8429 100644 --- a/htdocs/compta/loan/payment/payment.php +++ b/htdocs/compta/loan/payment/payment.php @@ -29,9 +29,10 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load("bills"); $langs->load("loan"); -$chid=GETPOST("id"); +$chid=GETPOST('id','int'); $action=GETPOST('action'); $amounts = array(); +$cancel=GETPOST('cancel','alpha'); // Security check $socid=0; @@ -47,7 +48,7 @@ if ($action == 'add_payment') { $error=0; - if ($_POST["cancel"]) + if ($cancel) { $loc = DOL_URL_ROOT.'/compta/loan/card.php?id='.$chid; header("Location: ".$loc); @@ -98,12 +99,15 @@ if ($action == 'add_payment') // Create a line of payments $payment = new PaymentLoan($db); - $payment->chid = $chid; - $payment->datepaid = $datepaid; - $payment->amounts = $amounts; // Tableau de montant - $payment->paymenttype = $_POST["paymenttype"]; - $payment->num_payment = $_POST["num_payment"]; - $payment->note = $_POST["note"]; + $payment->chid = $chid; + $payment->datepaid = $datepaid; + $payment->amounts = $amounts; // Tableau de montant + $payment->amount_capital = $_POST["amount_capital"]; + $payment->amount_insurance = $_POST["amount_insurance"]; + $payment->amount_interest = $_POST["amount_interest"]; + $payment->paymenttype = $_POST["paymenttype"]; + $payment->num_payment = $_POST["num_payment"]; + $payment->note = $_POST["note"]; if (! $error) { @@ -177,12 +181,12 @@ if ($_GET["action"] == 'create') print ''; - print ""; + print ''; print ''; - print '\n"; + print '\n"; print '\n"; - print ''; + print ''; $sql = "SELECT sum(p.amount) as total"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; @@ -204,7 +208,7 @@ if ($_GET["action"] == 'create') print '
".$langs->trans("Loan")."
'.$langs->trans("Loan").'
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("DateStart")."".dol_print_date($loan->datestart,'day')."
'.$langs->trans("DateStart").''.dol_print_date($loan->datestart,'day')."
'.$langs->trans("Label").''.$loan->label."
'.$langs->trans("Amount")."".price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Amount").''.price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).'
'; print ''; - print "'; + print ''; print ''; print ''; + print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''; print '\n"; print "\n"; print '\n"; @@ -457,25 +457,25 @@ if ($id > 0) // Edit if ($user->rights->loan->write) { - print "id&action=edit\">".$langs->trans("Modify").""; + print "id&action=edit\">".$langs->trans("Modify").""; } // Emit payment if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) { - print "id&action=create\">".$langs->trans("DoPayment").""; + print "id&action=create\">".$langs->trans("DoPayment").""; } // Classify 'paid' if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write) { - print "id&action=paid\">".$langs->trans("ClassifyPaid").""; + print "id&action=paid\">".$langs->trans("ClassifyPaid").""; } // Delete if ($user->rights->loan->delete) { - print "id&action=delete\">".$langs->trans("Delete").""; + print "id&action=delete\">".$langs->trans("Delete").""; } print ""; diff --git a/htdocs/compta/loan/class/index.html b/htdocs/loan/class/index.html similarity index 100% rename from htdocs/compta/loan/class/index.html rename to htdocs/loan/class/index.html diff --git a/htdocs/compta/loan/class/loan.class.php b/htdocs/loan/class/loan.class.php similarity index 99% rename from htdocs/compta/loan/class/loan.class.php rename to htdocs/loan/class/loan.class.php index b8fcf04728f..d1b770f744c 100644 --- a/htdocs/compta/loan/class/loan.class.php +++ b/htdocs/loan/class/loan.class.php @@ -16,7 +16,7 @@ */ /** - * \file htdocs/compta/loan/class/loan.class.php + * \file htdocs/loan/class/loan.class.php * \ingroup loan * \brief Class for loan module */ @@ -386,7 +386,7 @@ class Loan extends CommonObject $result=''; - $link = ''; + $link = ''; $linkend=''; if ($withpicto) $result.=($link.img_object($langs->trans("ShowLoan").': '.$this->label,'bill').$linkend.' '); diff --git a/htdocs/compta/loan/class/paymentloan.class.php b/htdocs/loan/class/paymentloan.class.php similarity index 98% rename from htdocs/compta/loan/class/paymentloan.class.php rename to htdocs/loan/class/paymentloan.class.php index 944cfe4ce2f..bb94a86d945 100644 --- a/htdocs/compta/loan/class/paymentloan.class.php +++ b/htdocs/loan/class/paymentloan.class.php @@ -16,7 +16,7 @@ */ /** - * \file htdocs/compta/loan/class/paymentloan.class.php + * \file htdocs/loan/class/paymentloan.class.php * \ingroup facture * \brief File of class to manage payment of loans */ @@ -429,7 +429,7 @@ class PaymentLoan extends CommonObject // Add link 'payment_loan' in bank_url between payment and bank transaction $url=''; - if ($mode == 'payment_loan') $url=DOL_URL_ROOT.'/compta/loan/payment/card.php?id='; + if ($mode == 'payment_loan') $url=DOL_URL_ROOT.'/loan/payment/card.php?id='; if ($url) { $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode); @@ -448,7 +448,7 @@ class PaymentLoan extends CommonObject { $loan = new Loan($this->db); $loan->fetch($key); - $result=$acc->add_url_line($bank_line_id, $loan->id, DOL_URL_ROOT.'/compta/loan/card.php?id=', $loan->type_libelle.(($loan->lib && $loan->lib!=$loan->type_libelle)?' ('.$loan->lib.')':''),'loan'); + $result=$acc->add_url_line($bank_line_id, $loan->id, DOL_URL_ROOT.'/loan/card.php?id=', $loan->type_libelle.(($loan->lib && $loan->lib!=$loan->type_libelle)?' ('.$loan->lib.')':''),'loan'); if ($result <= 0) dol_print_error($this->db); } } diff --git a/htdocs/compta/loan/document.php b/htdocs/loan/document.php similarity index 96% rename from htdocs/compta/loan/document.php rename to htdocs/loan/document.php index b263fa1687d..788048a215b 100644 --- a/htdocs/compta/loan/document.php +++ b/htdocs/loan/document.php @@ -16,13 +16,13 @@ */ /** - * \file htdocs/compta/loan/document.php + * \file htdocs/loan/document.php * \ingroup loan * \brief Page with attached files on loan */ -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; diff --git a/htdocs/compta/loan/index.html b/htdocs/loan/index.html similarity index 100% rename from htdocs/compta/loan/index.html rename to htdocs/loan/index.html diff --git a/htdocs/compta/loan/index.php b/htdocs/loan/index.php similarity index 97% rename from htdocs/compta/loan/index.php rename to htdocs/loan/index.php index 720b52de0a1..db6e9544cee 100644 --- a/htdocs/compta/loan/index.php +++ b/htdocs/loan/index.php @@ -16,13 +16,13 @@ */ /** - * \file htdocs/compta/loan/index.php + * \file htdocs/loan/index.php * \ingroup loan * \brief Page to list all loans */ -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; $langs->load("loan"); $langs->load("compta"); diff --git a/htdocs/compta/loan/info.php b/htdocs/loan/info.php similarity index 91% rename from htdocs/compta/loan/info.php rename to htdocs/loan/info.php index 74319ba40b8..5e90474642a 100644 --- a/htdocs/compta/loan/info.php +++ b/htdocs/loan/info.php @@ -16,13 +16,13 @@ */ /** - * \file htdocs/compta/loan/info.php + * \file htdocs/loan/info.php * \ingroup loan * \brief Page with info about loan */ -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; diff --git a/htdocs/compta/loan/payment/card.php b/htdocs/loan/payment/card.php similarity index 92% rename from htdocs/compta/loan/payment/card.php rename to htdocs/loan/payment/card.php index 4dc1407e8ad..901daffaa2d 100644 --- a/htdocs/compta/loan/payment/card.php +++ b/htdocs/loan/payment/card.php @@ -16,16 +16,14 @@ */ /** - * \file htdocs/compta/loan/payment/card.php + * \file htdocs/loan/payment/card.php * \ingroup loan * \brief Payment's card of loan */ -require '../../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/paymentloan.class.php'; -// require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; -// require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php'; if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load('bills'); @@ -62,7 +60,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->del if ($result > 0) { $db->commit(); - header("Location: ".DOL_URL_ROOT."/compta/loan/index.php"); + header("Location: ".DOL_URL_ROOT."/loan/index.php"); exit; } else @@ -122,7 +120,7 @@ $form = new Form($db); $h=0; -$head[$h][0] = DOL_URL_ROOT.'/compta/loan/payment/card.php?id='.$_GET["id"]; +$head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("Card"); $hselected = $h; $h++; @@ -205,7 +203,7 @@ $sql.= ' WHERE pl.fk_loan = l.rowid'; $sql.= ' AND l.entity = '.$conf->entity; $sql.= ' AND pl.rowid = '.$payment->id; -dol_syslog("compta/loan/payment/card.php", LOG_DEBUG); +dol_syslog("loan/payment/card.php", LOG_DEBUG); $resql=$db->query($sql); if ($resql) { diff --git a/htdocs/compta/loan/payment/index.html b/htdocs/loan/payment/index.html similarity index 100% rename from htdocs/compta/loan/payment/index.html rename to htdocs/loan/payment/index.html diff --git a/htdocs/compta/loan/payment/payment.php b/htdocs/loan/payment/payment.php similarity index 95% rename from htdocs/compta/loan/payment/payment.php rename to htdocs/loan/payment/payment.php index 678ca1b8429..9a087d60633 100644 --- a/htdocs/compta/loan/payment/payment.php +++ b/htdocs/loan/payment/payment.php @@ -16,14 +16,14 @@ */ /** - * \file htdocs/compta/loan/payment.php + * \file htdocs/loan/payment/payment.php * \ingroup Loan * \brief Page to add payment of a loan */ -require '../../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/paymentloan.class.php'; +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load("bills"); @@ -50,7 +50,7 @@ if ($action == 'add_payment') if ($cancel) { - $loc = DOL_URL_ROOT.'/compta/loan/card.php?id='.$chid; + $loc = DOL_URL_ROOT.'/loan/card.php?id='.$chid; header("Location: ".$loc); exit; } @@ -132,7 +132,7 @@ if ($action == 'add_payment') if (! $error) { $db->commit(); - $loc = DOL_URL_ROOT.'/compta/loan/card.php?id='.$chid; + $loc = DOL_URL_ROOT.'/loan/card.php?id='.$chid; header('Location: '.$loc); exit; } @@ -183,7 +183,7 @@ if ($_GET["action"] == 'create') print ''; - print ''; + print ''; print '\n"; print '\n"; print ''; From c4d852ffd73e3fa6af264aaf6a254ab3a80f1cfb Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 22 Mar 2015 20:57:41 +0100 Subject: [PATCH 22/24] Correct from frederic34 --- htdocs/langs/en_US/loan.lang | 1 + htdocs/loan/calc.php | 33 +++++++++++++++----------------- htdocs/loan/class/loan.class.php | 26 ++++++++++++++++++------- htdocs/loan/index.php | 13 +++++++------ htdocs/loan/info.php | 25 ++++++++++++++---------- htdocs/loan/payment/card.php | 21 ++++++++------------ 6 files changed, 65 insertions(+), 54 deletions(-) diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang index a035c8cf68c..4922c0fc0a1 100644 --- a/htdocs/langs/en_US/loan.lang +++ b/htdocs/langs/en_US/loan.lang @@ -20,6 +20,7 @@ ErrorLoanInterest=Annual interest has to be numeric and g # Calc Totalsforyear=Totals for year MonthlyPayment=Monthly Payment +LoanCalcDesc=This mortgage calculator can be used to figure out monthly payments of a home mortgage loan, based on the home's sale price, the term of the loan desired, buyer's down payment percentage, and the loan's interest rate.
This calculator factors in PMI (Private Mortgage Insurance) for loans where less than 20% is put as a down payment. Also taken into consideration are the town property taxes, and their effect on the total monthly mortgage payment.
# Admin ConfigLoan=Configuration of the module loan LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Accountancy code capital by default diff --git a/htdocs/loan/calc.php b/htdocs/loan/calc.php index 0b40ef38f70..0a5ee21923a 100644 --- a/htdocs/loan/calc.php +++ b/htdocs/loan/calc.php @@ -121,10 +121,7 @@ if (! empty($errors)) { llxHeader(); -echo "This mortgage calculator can be used to figure out monthly payments of a home mortgage loan, - based on the home's sale price, the term of the loan desired, buyer's down payment percentage, and the loan's interest rate. - This calculator factors in PMI (Private Mortgage Insurance) for loans where less than 20% is put as a down payment. Also taken - into consideration are the town property taxes, and their effect on the total monthly mortgage payment.
"; +print $langs->trans('LoanCalcDesc'); print ''; print ''; @@ -190,7 +187,7 @@ if ($form_complete && $monthly_payment) print '
'; print ''; print ''; - + if ($down_percent < 20) { $pmi_per_month = 55 * ($financing_price / 100000); @@ -216,11 +213,11 @@ if ($form_complete && $monthly_payment) print ''; print ''; print '
".$langs->trans("Payment").''.$langs->trans("Payment").'
'.$langs->trans("Date").''; @@ -249,10 +253,10 @@ if ($_GET["action"] == 'create') print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print "\n"; $var=True; @@ -269,24 +273,44 @@ if ($_GET["action"] == 'create') if ($objp->datestart > 0) { - print "\n"; + print ''; } else { - print "\n"; + print ''; } - print '"; + print '"; - print '"; + print '"; - print '"; + print '"; - print '"; print ''; - print ""; - print ""; - print ""; + print ''; + print ''; + print ''; print ''; print "\n"; } diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 95158c60a4f..0cbede46864 100755 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -1099,48 +1099,6 @@ CREATE TABLE llx_usergroup_extrafields ( ALTER TABLE llx_usergroup_extrafields ADD INDEX idx_usergroup_extrafields (fk_object); --- Loan -create table llx_loan -( - rowid integer AUTO_INCREMENT PRIMARY KEY, - entity integer DEFAULT 1 NOT NULL, - datec datetime, - tms timestamp, - label varchar(80) NOT NULL, - fk_bank integer, - capital real default 0 NOT NULL, - datestart date, - dateend date, - nbterm real, - rate double NOT NULL, - note text, - capital_position real default 0, - date_position date, - paid smallint default 0 NOT NULL, - accountancy_account_capital varchar(32), - accountancy_account_insurance varchar(32), - accountancy_account_interest varchar(32), - fk_user_author integer DEFAULT NULL, - fk_user_modif integer DEFAULT NULL, - active tinyint DEFAULT 1 NOT NULL -)ENGINE=innodb; - -create table llx_payment_loan -( - rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_loan integer, - datec datetime, - tms timestamp, - datep datetime, - amount real DEFAULT 0, - fk_typepayment integer NOT NULL, - num_payment varchar(50), - note text, - fk_bank integer NOT NULL, - fk_user_creat integer, - fk_user_modif integer -)ENGINE=innodb; - ALTER TABLE llx_contrat ADD COLUMN model_pdf varchar(255) DEFAULT NULL AFTER note_public; ALTER TABLE llx_c_country ADD COLUMN favorite tinyint DEFAULT 0 AFTER active; diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql new file mode 100644 index 00000000000..93f2197de12 --- /dev/null +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -0,0 +1,63 @@ +-- +-- Be carefull to requests order. +-- This file must be loaded by calling /install/index.php page +-- when current version is 3.8.0 or higher. +-- +-- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new; +-- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; +-- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); +-- To drop a column: ALTER TABLE llx_table DROP COLUMN oldname; +-- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60); +-- To drop a foreign key: ALTER TABLE llx_table DROP FOREIGN KEY fk_name; +-- To restrict request to Mysql version x.y use -- VMYSQLx.y +-- To restrict request to Pgsql version x.y use -- VPGSQLx.y +-- To make pk to be auto increment (mysql): VMYSQL4.3 ALTER TABLE llx_c_shipment_mode CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; +-- To make pk to be auto increment (postgres): VPGSQL8.2 NOT POSSIBLE. MUST DELETE/CREATE TABLE +-- To set a field as NULL: VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL; +-- To set a field as default NULL: VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET DEFAULT NULL; +-- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user); +-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); + +-- Loan +create table llx_loan +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, + datec datetime, + tms timestamp, + label varchar(80) NOT NULL, + fk_bank integer, + capital real default 0 NOT NULL, + datestart date, + dateend date, + nbterm real, + rate double NOT NULL, + note text, + capital_position real default 0, + date_position date, + paid smallint default 0 NOT NULL, + accountancy_account_capital varchar(32), + accountancy_account_insurance varchar(32), + accountancy_account_interest varchar(32), + fk_user_author integer DEFAULT NULL, + fk_user_modif integer DEFAULT NULL, + active tinyint DEFAULT 1 NOT NULL +)ENGINE=innodb; + +create table llx_payment_loan +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_loan integer, + datec datetime, + tms timestamp, + datep datetime, + amount_capital real DEFAULT 0, + amount_insurance real DEFAULT 0, + amount_interest real DEFAULT 0, + fk_typepayment integer NOT NULL, + num_payment varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, + fk_user_modif integer +)ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_payment_loan.sql b/htdocs/install/mysql/tables/llx_payment_loan.sql index 83bb3ac2548..0fb6b566ca5 100644 --- a/htdocs/install/mysql/tables/llx_payment_loan.sql +++ b/htdocs/install/mysql/tables/llx_payment_loan.sql @@ -23,7 +23,9 @@ create table llx_payment_loan datec datetime, -- creation date tms timestamp, datep datetime, -- payment date - amount real DEFAULT 0, + amount_capital real DEFAULT 0, + amount_insurance real DEFAULT 0, + amount_interest real DEFAULT 0, fk_typepayment integer NOT NULL, num_payment varchar(50), note text, diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang index 10fb0249f6d..9ccff4eecf4 100644 --- a/htdocs/langs/en_US/loan.lang +++ b/htdocs/langs/en_US/loan.lang @@ -5,10 +5,13 @@ NewLoan=New Loan ShowLoan=Show Loan PaymentLoan=Loan payment Capital=Capital +Insurance=Insurance +Interest=Interest Nbterms=Number of terms LoanAccountancyCapitalCode=Accountancy code capital LoanAccountancyInsuranceCode=Accountancy code insurance LoanAccountancyInterestCode=Accountancy code interest +LoanPayment=Loan payment ConfirmDeleteLoan=Confirm deleting this loan ConfirmPayLoan=Confirm classify paid this loan ErrorLoanCapital=Loan amount has to be numeric and greater than zero. diff --git a/htdocs/langs/fr_FR/loan.lang b/htdocs/langs/fr_FR/loan.lang index 1e54f90e2be..0a5c6320d5b 100644 --- a/htdocs/langs/fr_FR/loan.lang +++ b/htdocs/langs/fr_FR/loan.lang @@ -5,10 +5,13 @@ NewLoan=Nouvel emprunt ShowLoan=Voir emprunt PaymentLoan=Règlement d'emprunt Capital=Capital +Insurance=Assurance +Interest=Intérêt Nbterms=Nombre d'échéances LoanAccountancyCapitalCode=Compte comptable capital LoanAccountancyInsuranceCode=Compte comptable assurance LoanAccountancyInterestCode=Compte comptable intérêts +LoanPayment=Règlement emprunt ConfirmDeleteLoan=Confirmation de supression de cet emprunt ConfirmPayLoan=Confirmation que cet emprunt est classé comme payé ErrorLoanCapital=Le capital de l'emprunt doit être au format numérique et supérieur à zéro. From 15e44b6e28bc873e20a45133df22679167e02346 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 10 Nov 2014 06:39:37 +0100 Subject: [PATCH 15/24] Correct Auguria menu --- htdocs/core/menus/init_menu_auguria.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index a4833551f5b..bf35ac2806e 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -179,8 +179,8 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled && $leftmenu=="tax_salary"', __HANDLER__, 'left', 2211__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/salaries/card.php?leftmenu=tax_salary&action=create', 'NewPayment', 2, 'companies', '$user->rights->salaries->write', '', 0, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled && $leftmenu=="tax_salary"', __HANDLER__, 'left', 2212__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/salaries/index.php?leftmenu=tax_salary', 'Payments', 2, 'companies', '$user->rights->salaries->read', '', 0, 3, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled', __HANDLER__, 'left', 2220__+MAX_llx_menu__, 'accountancy', 'tax_loan', 2200__+MAX_llx_menu__, '/compta/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy', 'Loans', 1, 'loan', '$user->rights->loan->read', '', 0, 1, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2221__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/loan/card.php?leftmenu=tax_loan&action=create', 'NewLoan', 2, 'loan', '$user->rights->loan->write', '', 0, 2, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2222__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/loan/index.php?leftmenu=tax_loan', 'Payments', 2, 'companies', '$user->rights->loan->read', '', 0, 3, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2221__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/compta/loan/card.php?leftmenu=tax_loan&action=create', 'NewLoan', 2, 'loan', '$user->rights->loan->write', '', 0, 2, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2222__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/compta/loan/index.php?leftmenu=tax_loan', 'Payments', 2, 'companies', '$user->rights->loan->read', '', 0, 3, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled', __HANDLER__, 'left', 2250__+MAX_llx_menu__, 'accountancy', 'tax_social', 2200__+MAX_llx_menu__, '/compta/sociales/index.php?leftmenu=tax_social', 'SocialContributions', 1, '', '$user->rights->tax->charges->lire', '', 0, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled && $leftmenu=="tax_social"', __HANDLER__, 'left', 2251__+MAX_llx_menu__, 'accountancy', '', 2250__+MAX_llx_menu__, '/compta/sociales/charges.php?leftmenu=tax_social&action=create', 'MenuNewSocialContribution', 2, '', '$user->rights->tax->charges->creer', '', 0, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled && $leftmenu=="tax_social"', __HANDLER__, 'left', 2252__+MAX_llx_menu__, 'accountancy', '', 2250__+MAX_llx_menu__, '/compta/charges/index.php?leftmenu=tax_social&mainmenu=accountancy&mode=sconly', 'Payments', 2, '', '$user->rights->tax->charges->lire', '', 0, 3, __ENTITY__); From c70539b3b220755594ffd4432f433fbdd7cd3c15 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Wed, 12 Nov 2014 07:33:03 +0100 Subject: [PATCH 16/24] Bug & merge --- htdocs/compta/bank/account.php | 2 +- htdocs/fichinter/card.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index 858df658158..875fb4a7ab2 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -727,7 +727,7 @@ if ($id > 0 || ! empty($ref)) $loanstatic->label=$links[$key]['label']; } $loanstatic->ref=$loanstatic->label; - print $loanstatic->getNameUrl(1,16); + print $loanstatic->getLinkUrl(1,16); } else if ($links[$key]['type']=='member') { diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 77c7e17ffb5..4ffc31c9cab 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -748,10 +748,10 @@ if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MA $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto; if ($message) { - if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc); - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject); - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":"); - $actionmsg = dol_concatdesc($actionmsg, $message); + if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc); + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject); + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":"); + $actionmsg = dol_concatdesc($actionmsg, $message); } $actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref); } From d15ef855da78952f3258c788ead2ba82aff75744 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Wed, 12 Nov 2014 07:37:59 +0100 Subject: [PATCH 17/24] Correct travis --- htdocs/langs/tr_TR/main.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/tr_TR/main.lang b/htdocs/langs/tr_TR/main.lang index 87b19cf7d91..63a4c3904c9 100644 --- a/htdocs/langs/tr_TR/main.lang +++ b/htdocs/langs/tr_TR/main.lang @@ -7,7 +7,7 @@ DIRECTION=ltr FONTFORPDF=DejaVuSans FONTSIZEFORPDF=8 SeparatorDecimal=, -SeparatorThousand=, +SeparatorThousand=Space FormatDateShort=%d/%m/%Y FormatDateShortInput=%d/%m/%Y FormatDateShortJava=dd/MM/yyyy From 31b90cf3834b48f4fda5ab2f5b41a56326935943 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 17 Nov 2014 06:38:06 +0100 Subject: [PATCH 18/24] Add 1st version of calculator but need work --- htdocs/compta/loan/calc.php | 385 ++++++++++++++++++++++++ htdocs/core/menus/init_menu_auguria.sql | 1 + htdocs/core/menus/standard/eldy.lib.php | 1 + htdocs/core/modules/modLoan.class.php | 8 + htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/en_US/loan.lang | 2 + 6 files changed, 398 insertions(+) create mode 100644 htdocs/compta/loan/calc.php diff --git a/htdocs/compta/loan/calc.php b/htdocs/compta/loan/calc.php new file mode 100644 index 00000000000..5cc2c830094 --- /dev/null +++ b/htdocs/compta/loan/calc.php @@ -0,0 +1,385 @@ + + * Copyright (C) 2014 Alexandre Spangaro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +require '../../main.inc.php'; + +$langs->load("loan"); + +/* --------------------------------------------------- * + * Set Form DEFAULT values + * --------------------------------------------------- */ +$default_sale_price = "150000"; +$default_annual_interest_percent = 7.0; +$default_year_term = 30; +$default_down_percent = 10; +$default_show_progress = TRUE; + +/* --------------------------------------------------- * + * Initialize Variables + * --------------------------------------------------- */ +$sale_price = 0; +$annual_interest_percent = 0; +$year_term = 0; +$down_percent = 0; +$this_year_interest_paid = 0; +$this_year_principal_paid = 0; +$form_complete = false; +$show_progress = false; +$monthly_payment = false; +$show_progress = false; +$error = false; + +/* --------------------------------------------------- * + * Set the USER INPUT values + * --------------------------------------------------- */ +if (isset($_REQUEST['form_complete'])) { + $sale_price = $_REQUEST['sale_price']; + $annual_interest_percent = $_REQUEST['annual_interest_percent']; + $year_term = $_REQUEST['year_term']; + $down_percent = $_REQUEST['down_percent']; + $show_progress = (isset($_REQUEST['show_progress'])) ? $_REQUEST['show_progress'] : false; + $form_complete = $_REQUEST['form_complete']; +} + +// This function does the actual mortgage calculations +// by plotting a PVIFA (Present Value Interest Factor of Annuity) +// table... +function get_interest_factor($year_term, $monthly_interest_rate) { + global $base_rate; + + $factor = 0; + $base_rate = 1 + $monthly_interest_rate; + $denominator = $base_rate; + for ($i=0; $i < ($year_term * 12); $i++) { + $factor += (1 / $denominator); + $denominator *= $base_rate; + } + return $factor; +} + +// If the form is complete, we'll start the math +if ($form_complete) { + // We'll set all the numeric values to JUST + // numbers - this will delete any dollars signs, + // commas, spaces, and letters, without invalidating + // the value of the number + $sale_price = preg_replace( "[^0-9.]", "", $sale_price); + $annual_interest_percent = preg_replace( "[^0-9.]", "", $annual_interest_percent); + $year_term = preg_replace( "[^0-9.]", "", $year_term); + $down_percent = preg_replace( "[^0-9.]", "", $down_percent); + + if (((float) $year_term <= 0) || ((float) $sale_price <= 0) || ((float) $annual_interest_percent <= 0)) { + $error = "You must enter a Sale Price of Home, Length of Motgage and Annual Interest Rate"; + } + + if (!$error) { + $month_term = $year_term * 12; + $down_payment = $sale_price * ($down_percent / 100); + $annual_interest_rate = $annual_interest_percent / 100; + $monthly_interest_rate = $annual_interest_rate / 12; + $financing_price = $sale_price - $down_payment; + $monthly_factor = get_interest_factor($year_term, $monthly_interest_rate); + $monthly_payment = $financing_price / $monthly_factor; + } +} else { + if (!$sale_price) { $sale_price = $default_sale_price; } + if (!$annual_interest_percent) { $annual_interest_percent = $default_annual_interest_percent; } + if (!$year_term) { $year_term = $default_year_term; } + if (!$down_percent) { $down_percent = $default_down_percent; } + if (!$show_progress) { $show_progress = $default_show_progress; } +} + +if ($error) { + print("" . $error . "

\n"); + $form_complete = false; +} + +/* + * View + */ + +llxHeader(); + +echo "This mortgage calculator can be used to figure out monthly payments of a home mortgage loan, + based on the home's sale price, the term of the loan desired, buyer's down payment percentage, and the loan's interest rate. + This calculator factors in PMI (Private Mortgage Insurance) for loans where less than 20% is put as a down payment. Also taken + into consideration are the town property taxes, and their effect on the total monthly mortgage payment.
"; + +print ''; +print ''; +print '
'.$langs->trans("DateDue").''.$langs->trans("Amount").''.$langs->trans("Capital").''.$langs->trans("AlreadyPaid").''.$langs->trans("RemainderToPay").''.$langs->trans("Amount").''.$langs->trans("Amount").'
".dol_print_date($objp->datestart,'day')."'.dol_print_date($objp->datestart,'day').'!!!!!!'.price($objp->capital)."'.price($objp->capital)."'.price($sumpaid)."'.price($sumpaid)."'.price($objp->capital - $sumpaid)."'.price($objp->capital - $sumpaid)."'; + print ''; if ($sumpaid < $objp->capital) { - $namef = "amount_".$objp->id; - print ''; + $namec = "amount_capital_".$objp->id; + print $langs->trans("Capital") .': '; + } + else + { + print '-'; + } + print '
'; + if ($sumpaid < $objp->capital) + { + $namea = "amount_insurance_".$objp->id; + print $langs->trans("Insurance") .': '; + } + else + { + print '-'; + } + print '
'; + if ($sumpaid < $objp->capital) + { + $namei = "amount_interest_".$objp->id; + print $langs->trans("Interest") .': '; } else { @@ -305,9 +329,9 @@ if ($_GET["action"] == 'create') // Print total print "
'.$langs->trans("Total").':".price($total_ttc)."".price($totalrecu)."".price($total_ttc - $totalrecu).""'.price($total_ttc).'""'.price($totalrecu).'""'.price($total_ttc - $totalrecu).'" 
'; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +if (! empty($show_progress)) +{ + print ''; +} +else +{ + print ''; +} + +print ''; +print '
Purchase & Financing Information
Sale Price of Home: '.$langs->trans("Currency".$conf->currency).'
Percentage Down:%
Length of Mortgage:years
Annual Interest Rate:%
Explain Calculations:Show me the calculations and amortizationShow me the calculations and amortization
'; + +print '
    '; +print '
'; + +// If the form has already been calculated, the $down_payment +// and $monthly_payment variables will be figured out, so we can show them in this table +if ($form_complete && $monthly_payment) +{ + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + if ($down_percent < 20) + { + $pmi_per_month = 55 * ($financing_price / 100000); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; +} + +print '
Mortgage Payment Information
Down Payment:' . number_format($down_payment, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '
Amount Financed:' . number_format($financing_price, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '
Monthly Payment:' . number_format($monthly_payment, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '
(Principal & Interest ONLY)
 '; + print '
'; + echo 'Since you are putting LESS than 20% down, you will need to pay PMI + (Private Mortgage Insurance), which tends + to be about $55 per month for every $100,000 financed (until you have paid off 20% of your loan). This could add + '."\$" . number_format($pmi_per_month, "2", ".", ",").' to your monthly payment.'; + print '
Monthly Payment:' . number_format(($monthly_payment + $pmi_per_month), "2", ".", ",") . $langs->trans("Currency".$conf->currency) . '
'; + print '(Principal & Interest, and PMI)
 '; + print '
'; + + $assessed_price = ($sale_price * .85); + $residential_yearly_tax = ($assessed_price / 1000) * 14; + $residential_monthly_tax = $residential_yearly_tax / 12; + + if ($pmi_per_month) + { + $pmi_text = "PMI and "; + } + + echo "Residential (or Property) Taxes are a little harder to figure out... In Massachusetts, the average resedential tax rate seems + to be around $14 per year for every $1,000 of your property's assessed value."; + + print '

'; + print "Let's say that your property's assessed value is 85% of what you actually paid for it - "; + print number_format($assessed_price, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . 'This would mean that your yearly residential taxes will be around'; + print number_format($residential_yearly_tax, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency); + print 'This could add ' . number_format($residential_monthly_tax, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . 'to your monthly payment'; + print '
TOTAL Monthly Payment:' . number_format(($monthly_payment + $pmi_per_month + $residential_monthly_tax), "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '
'; + print '(including '.$pmi_text.' residential tax)
'; +print ''; + +// This prints the calculation progress and +// the instructions of HOW everything is figured +// out +if ($form_complete && $show_progress) { + $step = 1; + + print '

'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'. $step++ .''; + echo 'The down payment + = The price of the home multiplied by the percentage down divided by 100 (for 5% down becomes 5/100 or 0.05)

+ ' . number_format($down_payment,"2",".",",") . ' ' . $langs->trans("Currency".$conf->currency) . ' = '.number_format($sale_price,"2",".",",") . ' ' . $langs->trans("Currency".$conf->currency) . ' X + ('.$down_percent.' / 100)'; + print '
' . $step++ . ''; + print 'The interest rate = The annual interest percentage divided by 100

'; + print $annual_interest_rate . ' = ' . $annual_interest_percent . '% / 100'; + print '
'; + print 'The monthly factor = The result of the following formula:'; + print '
' . $step++ . ''; + print 'The monthly interest rate = The annual interest rate divided by 12 (for the 12 months in a year)

'; + print $monthly_interest_rate . ' = ' . $annual_interest_rate . ' / 12'; + print '
' . $step++ . ''; + print 'The month term of the loan in months = The number of years you\'ve taken the loan out for times 12

'; + print $month_term . ' Months = ' . $year_term . ' Years X 12'; + print '
' . $step++ . ''; + print 'The montly payment is figured out using the following formula:
'; + print 'Monthly Payment = ' . number_format($financing_price, "2", "", "") . ' * '; + print number_format($monthly_interest_rate, "4", "", "") . ' / '; + print '(1 - ((1 + ' . number_format($monthly_interest_rate, "4", "", "") . ')'; + print '-(' . $month_term . '))))'; + print '

'; + print 'The amortization breaks down how much of your monthly payment goes towards the bank\'s interest,'; + print 'and how much goes into paying off the principal of your loan.'; + print '
'; + print '
'; + + + // Set some base variables + $principal = $financing_price; + $current_month = 1; + $current_year = 1; + + // This basically, re-figures out the monthly payment, again. + $power = -($month_term); + $denom = pow((1 + $monthly_interest_rate), $power); + $monthly_payment = $principal * ($monthly_interest_rate / (1 - $denom)); + + print("

Amortization For Monthly Payment: \$" . number_format($monthly_payment, "2", ".", ",") . " over " . $year_term . " years
\n"); + + print ''; + + // This LEGEND will get reprinted every 12 months + $legend = ''; + $legend.= ''; + $legend.= ''; + $legend.= ''; + $legend.= ''; + $legend.= ''; + + echo $legend; + + // Loop through and get the current month's payments for + // the length of the loan + while ($current_month <= $month_term) + { + $interest_paid = $principal * $monthly_interest_rate; + $principal_paid = $monthly_payment - $interest_paid; + $remaining_balance = $principal - $principal_paid; + + $this_year_interest_paid = $this_year_interest_paid + $interest_paid; + $this_year_principal_paid = $this_year_principal_paid + $principal_paid; + + $var = !$var; + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + + ($current_month % 12) ? $show_legend = FALSE : $show_legend = TRUE; + + if ($show_legend) { + print ''; + print ''; + print ''; + + $total_spent_this_year = $this_year_interest_paid + $this_year_principal_paid; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + + $current_year++; + $this_year_interest_paid = 0; + $this_year_principal_paid = 0; + + if (($current_month + 6) < $month_term) + { + echo $legend; + } + } + $principal = $remaining_balance; + $current_month++; + } + print("
' . $langs->trans("Month") . '' . $langs->trans("Interest") . '' . $langs->trans("Capital") . '' . $langs->trans("Position") . '
' . $current_month . '' . number_format($interest_paid, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '' . number_format($principal_paid, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '' . number_format($remaining_balance, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '
' . $langs->trans("Totalsforyear") . ' ' . $current_year . '
 '; + print 'You will spend ' . number_format($total_spent_this_year, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . ' on your house in year ' . $current_year . '
'; + print number_format($this_year_interest_paid, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . ' will go towards INTEREST
'; + print number_format($this_year_principal_paid, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . ' will go towards PRINCIPAL
'; + print '
 
\n"); +} + +llxFooter(); + +$db->close(); diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index bf35ac2806e..a0a91cab781 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -181,6 +181,7 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled', __HANDLER__, 'left', 2220__+MAX_llx_menu__, 'accountancy', 'tax_loan', 2200__+MAX_llx_menu__, '/compta/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy', 'Loans', 1, 'loan', '$user->rights->loan->read', '', 0, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2221__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/compta/loan/card.php?leftmenu=tax_loan&action=create', 'NewLoan', 2, 'loan', '$user->rights->loan->write', '', 0, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2222__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/compta/loan/index.php?leftmenu=tax_loan', 'Payments', 2, 'companies', '$user->rights->loan->read', '', 0, 3, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2223__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/compta/loan/calc.php?leftmenu=tax_loan', 'Calculator', 2, 'companies', '$user->rights->loan->calc', '', 0, 4, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled', __HANDLER__, 'left', 2250__+MAX_llx_menu__, 'accountancy', 'tax_social', 2200__+MAX_llx_menu__, '/compta/sociales/index.php?leftmenu=tax_social', 'SocialContributions', 1, '', '$user->rights->tax->charges->lire', '', 0, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled && $leftmenu=="tax_social"', __HANDLER__, 'left', 2251__+MAX_llx_menu__, 'accountancy', '', 2250__+MAX_llx_menu__, '/compta/sociales/charges.php?leftmenu=tax_social&action=create', 'MenuNewSocialContribution', 2, '', '$user->rights->tax->charges->creer', '', 0, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled && $leftmenu=="tax_social"', __HANDLER__, 'left', 2252__+MAX_llx_menu__, 'accountancy', '', 2250__+MAX_llx_menu__, '/compta/charges/index.php?leftmenu=tax_social&mainmenu=accountancy&mode=sconly', 'Payments', 2, '', '$user->rights->tax->charges->lire', '', 0, 3, __ENTITY__); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 87c88ac028c..61ad1a4163f 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -817,6 +817,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy",$langs->trans("Loans"),1,$user->rights->loan->read, '', $mainmenu, 'tax_loan'); if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/card.php?leftmenu=tax_loan&action=create",$langs->trans("NewLoan"),2,$user->rights->loan->write); if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read); + if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/calc.php?leftmenu=tax_loan",$langs->trans("Calculator"),2,$user->rights->loan->calc); } // Social contributions diff --git a/htdocs/core/modules/modLoan.class.php b/htdocs/core/modules/modLoan.class.php index fb2de1e3a02..21ae96eba26 100644 --- a/htdocs/core/modules/modLoan.class.php +++ b/htdocs/core/modules/modLoan.class.php @@ -118,6 +118,14 @@ class modLoan extends DolibarrModules $this->rights[$r][3] = 0; $this->rights[$r][4] = 'delete'; $this->rights[$r][5] = ''; + + $r++; + $this->rights[$r][0] = 525; + $this->rights[$r][1] = 'Access loan calculator'; + $this->rights[$r][2] = 'r'; + $this->rights[$r][3] = 0; + $this->rights[$r][4] = 'calc'; + $this->rights[$r][5] = ''; $r++; $this->rights[$r][0] = 527; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index a56a68f3b66..b1d69ae015d 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -698,6 +698,7 @@ Permission517=Export salaries Permission520=Read Loans Permission522=Create/modify loans Permission524=Delete loans +Permission525=Access loan calculator Permission527=Export loans Permission531=Read services Permission532=Create/modify services diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang index 9ccff4eecf4..e59fc7898b8 100644 --- a/htdocs/langs/en_US/loan.lang +++ b/htdocs/langs/en_US/loan.lang @@ -17,6 +17,8 @@ ConfirmPayLoan=Confirm classify paid this loan ErrorLoanCapital=Loan amount has to be numeric and greater than zero. ErrorLoanLength=Loan length has to be numeric and greater than zero. ErrorLoanInterest=Annual interest has to be numeric and greater than zero. +# Calc +Totalsforyear=Totals for year # Admin ConfigLoan=Configuration of the module loan LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Accountancy code capital by default From 3aa6c8c855969737450dff601a2b2609b78301d9 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sat, 21 Feb 2015 15:19:18 +0100 Subject: [PATCH 19/24] Correct auguria menu --- htdocs/core/menus/init_menu_auguria.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index 85e4ab3e8f1..b0a001a4818 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -12,7 +12,7 @@ insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, left insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('societe|fournisseur', '( ! empty($conf->societe->enabled) && (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))) || ! empty($conf->fournisseur->enabled)', 2__+MAX_llx_menu__, __HANDLER__, 'top', 'companies', '', 0, '/societe/index.php?mainmenu=companies&leftmenu=', 'ThirdParties', -1, 'companies', '$user->rights->societe->lire || $user->rights->societe->contact->lire', '', 2, 20, __ENTITY__); insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('product|service', '$conf->product->enabled || $conf->service->enabled', 3__+MAX_llx_menu__, __HANDLER__, 'top', 'products', '', 0, '/product/index.php?mainmenu=products&leftmenu=', 'Products/Services', -1, 'products', '$user->rights->produit->lire||$user->rights->service->lire', '', 0, 30, __ENTITY__); insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('propal|commande|fournisseur|contrat|ficheinter', '$conf->propal->enabled || $conf->commande->enabled || $conf->fournisseur->enabled || $conf->contrat->enabled || $conf->ficheinter->enabled', 5__+MAX_llx_menu__, __HANDLER__, 'top', 'commercial', '', 0, '/comm/index.php?mainmenu=commercial&leftmenu=', 'Commercial', -1, 'commercial', '$user->rights->societe->lire || $user->rights->societe->contact->lire', '', 2, 40, __ENTITY__); -insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('comptabilite|accounting|facture|deplacement|don|tax|salaries', '$conf->comptabilite->enabled || $conf->accounting->enabled || $conf->facture->enabled || $conf->deplacement->enabled || $conf->don->enabled || $conf->tax->enabled || $conf->salaries->enabled', 6__+MAX_llx_menu__, __HANDLER__, 'top', 'accountancy', '', 0, '/compta/index.php?mainmenu=accountancy&leftmenu=', 'MenuFinancial', -1, 'compta', '$user->rights->compta->resultat->lire || $user->rights->accounting->plancompte->lire || $user->rights->facture->lire|| $user->rights->deplacement->lire || $user->rights->don->lire || $user->rights->tax->charges->lire || $user->rights->salaries->read', '', 2, 50, __ENTITY__); +insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('comptabilite|accounting|facture|deplacement|don|tax|salaries|loan', '$conf->comptabilite->enabled || $conf->accounting->enabled || $conf->facture->enabled || $conf->deplacement->enabled || $conf->don->enabled || $conf->tax->enabled || $conf->salaries->enabled || $conf->loan->enabled', 6__+MAX_llx_menu__, __HANDLER__, 'top', 'accountancy', '', 0, '/compta/index.php?mainmenu=accountancy&leftmenu=', 'MenuFinancial', -1, 'compta', '$user->rights->compta->resultat->lire || $user->rights->accounting->plancompte->lire || $user->rights->facture->lire|| $user->rights->deplacement->lire || $user->rights->don->lire || $user->rights->tax->charges->lire || $user->rights->salaries->read || $user->rights->loan->read', '', 2, 50, __ENTITY__); insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('banque|prelevement', '$conf->banque->enabled || $conf->prelevement->enabled', 14__+MAX_llx_menu__, __HANDLER__, 'top', 'bank', '', 0, '/compta/bank/index.php?mainmenu=bank&leftmenu=bank', 'MenuBankCash', -1, 'banks', '$user->rights->banque->lire || $user->rights->prelevement->bons->lire', '', 0, 60, __ENTITY__); insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('projet', '$conf->projet->enabled', 7__+MAX_llx_menu__, __HANDLER__, 'top', 'project', '', 0, '/projet/index.php?mainmenu=project&leftmenu=', 'Projects', -1, 'projects', '$user->rights->projet->lire', '', 2, 70, __ENTITY__); insert into llx_menu (module, enabled, rowid, menu_handler, type, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('mailing|export|import|opensurvey', '$conf->mailing->enabled || $conf->export->enabled || $conf->import->enabled || $conf->opensurvey->enabled', 8__+MAX_llx_menu__, __HANDLER__, 'top', 'tools', '', 0, '/core/tools.php?mainmenu=tools&leftmenu=', 'Tools', -1, 'other', '$user->rights->mailing->lire || $user->rights->export->lire || $user->rights->import->run || $user->rights->opensurvey->read', '', 2, 90, __ENTITY__); From 8c6a50554ee02e41fee21b81109fa8aa74f6faa1 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Thu, 5 Mar 2015 20:37:36 +0100 Subject: [PATCH 20/24] Debug of Frederic34. Thanks ! --- htdocs/compta/loan/calc.php | 43 ++++++++++++++++++++---------------- htdocs/langs/en_US/loan.lang | 1 + 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/htdocs/compta/loan/calc.php b/htdocs/compta/loan/calc.php index 5cc2c830094..009c61095c9 100644 --- a/htdocs/compta/loan/calc.php +++ b/htdocs/compta/loan/calc.php @@ -1,6 +1,7 @@ * Copyright (C) 2014 Alexandre Spangaro + * Copyright (C) 2015 Frederic France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +20,7 @@ require '../../main.inc.php'; $langs->load("loan"); - + /* --------------------------------------------------- * * Set Form DEFAULT values * --------------------------------------------------- */ @@ -82,12 +83,17 @@ if ($form_complete) { $annual_interest_percent = preg_replace( "[^0-9.]", "", $annual_interest_percent); $year_term = preg_replace( "[^0-9.]", "", $year_term); $down_percent = preg_replace( "[^0-9.]", "", $down_percent); - - if (((float) $year_term <= 0) || ((float) $sale_price <= 0) || ((float) $annual_interest_percent <= 0)) { - $error = "You must enter a Sale Price of Home, Length of Motgage and Annual Interest Rate"; - } - if (!$error) { + if ((float) $year_term <= 0) { + $errors[] = "You must enter a Sale Price of Home"; + } + if ((float) $sale_price <= 0) { + $errors[] = "You must enter a Length of Mortgage"; + } + if ((float) $annual_interest_percent <= 0) { + $errors[] = "You must enter an Annual Interest Rate"; + } + if (!$errors) { $month_term = $year_term * 12; $down_payment = $sale_price * ($down_percent / 100); $annual_interest_rate = $annual_interest_percent / 100; @@ -104,8 +110,8 @@ if ($form_complete) { if (!$show_progress) { $show_progress = $default_show_progress; } } -if ($error) { - print("" . $error . "

\n"); +if (! empty($errors)) { + setEventMessages('', $errors, 'errors'); $form_complete = false; } @@ -123,17 +129,16 @@ echo "This mortgage calculator can be use print '
'; print ''; print ''; -print ''; -print ''; -print ''; -print ''; +//print ''; +//print ''; +//print ''; +//print ''; print ''; print ''; print ''; print ''; print ''; -print ''; -print ''; +print '';print ''; print ''; print ''; print ''; @@ -289,7 +294,7 @@ if ($form_complete && $show_progress) { print '
Purchase & Financing Information
Sale Price of Home: '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("Currency".$conf->currency).'
Percentage Down:%'; print 'The montly payment is figured out using the following formula:
'; print 'Monthly Payment = ' . number_format($financing_price, "2", "", "") . ' * '; - print number_format($monthly_interest_rate, "4", "", "") . ' / '; + print $langs->trans('MonthlyPayment').' = ' . number_format($financing_price, "2", "", "") . ' * '; print '(1 - ((1 + ' . number_format($monthly_interest_rate, "4", "", "") . ')'; print '-(' . $month_term . '))))'; print '

'; @@ -311,7 +316,7 @@ if ($form_complete && $show_progress) { $denom = pow((1 + $monthly_interest_rate), $power); $monthly_payment = $principal * ($monthly_interest_rate / (1 - $denom)); - print("

Amortization For Monthly Payment: \$" . number_format($monthly_payment, "2", ".", ",") . " over " . $year_term . " years
\n"); + print "

Amortization For Monthly Payment: " . number_format($monthly_payment, "2", ".", ",") . " over " . $year_term . " years
\n"); print ''; @@ -323,8 +328,8 @@ if ($form_complete && $show_progress) { $legend.= ''; $legend.= ''; - echo $legend; - + print $legend; + // Loop through and get the current month's payments for // the length of the loan while ($current_month <= $month_term) @@ -377,7 +382,7 @@ if ($form_complete && $show_progress) { $principal = $remaining_balance; $current_month++; } - print("
' . $langs->trans("Position") . '
\n"); + print "
\n"; } llxFooter(); diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang index e59fc7898b8..a035c8cf68c 100644 --- a/htdocs/langs/en_US/loan.lang +++ b/htdocs/langs/en_US/loan.lang @@ -19,6 +19,7 @@ ErrorLoanLength=Loan length has to be numeric and greater ErrorLoanInterest=Annual interest has to be numeric and greater than zero. # Calc Totalsforyear=Totals for year +MonthlyPayment=Monthly Payment # Admin ConfigLoan=Configuration of the module loan LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Accountancy code capital by default From ad0f1aae6bc1eaff3f0d8f660735e590fac5e8c4 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 22 Mar 2015 20:19:22 +0100 Subject: [PATCH 21/24] Move loan in htdocs --- htdocs/core/lib/loan.lib.php | 6 +++--- htdocs/core/menus/init_menu_auguria.sql | 8 ++++---- htdocs/core/menus/standard/eldy.lib.php | 8 ++++---- htdocs/{compta => }/loan/calc.php | 2 +- htdocs/{compta => }/loan/card.php | 16 ++++++++-------- htdocs/{compta => }/loan/class/index.html | 0 htdocs/{compta => }/loan/class/loan.class.php | 4 ++-- .../loan/class/paymentloan.class.php | 6 +++--- htdocs/{compta => }/loan/document.php | 6 +++--- htdocs/{compta => }/loan/index.html | 0 htdocs/{compta => }/loan/index.php | 6 +++--- htdocs/{compta => }/loan/info.php | 6 +++--- htdocs/{compta => }/loan/payment/card.php | 16 +++++++--------- htdocs/{compta => }/loan/payment/index.html | 0 htdocs/{compta => }/loan/payment/payment.php | 14 +++++++------- 15 files changed, 48 insertions(+), 50 deletions(-) rename htdocs/{compta => }/loan/calc.php (99%) rename htdocs/{compta => }/loan/card.php (94%) rename htdocs/{compta => }/loan/class/index.html (100%) rename htdocs/{compta => }/loan/class/loan.class.php (99%) rename htdocs/{compta => }/loan/class/paymentloan.class.php (98%) rename htdocs/{compta => }/loan/document.php (96%) rename htdocs/{compta => }/loan/index.html (100%) rename htdocs/{compta => }/loan/index.php (97%) rename htdocs/{compta => }/loan/info.php (91%) rename htdocs/{compta => }/loan/payment/card.php (92%) rename htdocs/{compta => }/loan/payment/index.html (100%) rename htdocs/{compta => }/loan/payment/payment.php (95%) diff --git a/htdocs/core/lib/loan.lib.php b/htdocs/core/lib/loan.lib.php index 58ebaef7bfd..323516bbbd6 100644 --- a/htdocs/core/lib/loan.lib.php +++ b/htdocs/core/lib/loan.lib.php @@ -35,7 +35,7 @@ function loan_prepare_head($object) $h = 0; $head = array(); - $head[$h][0] = DOL_URL_ROOT.'/compta/loan/card.php?id='.$object->id; + $head[$h][0] = DOL_URL_ROOT.'/loan/card.php?id='.$object->id; $head[$h][1] = $langs->trans('Card'); $head[$h][2] = 'card'; $h++; @@ -49,13 +49,13 @@ function loan_prepare_head($object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $upload_dir = $conf->loan->dir_output . "/" . dol_sanitizeFileName($object->ref); $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); - $head[$h][0] = DOL_URL_ROOT.'/compta/loan/document.php?id='.$object->id; + $head[$h][0] = DOL_URL_ROOT.'/loan/document.php?id='.$object->id; $head[$h][1] = $langs->trans("Documents"); if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')'; $head[$h][2] = 'documents'; $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/loan/info.php?id='.$object->id; + $head[$h][0] = DOL_URL_ROOT.'/loan/info.php?id='.$object->id; $head[$h][1] = $langs->trans("Info"); $head[$h][2] = 'info'; $h++; diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index a2d77f611f0..c385eaab4bf 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -181,10 +181,10 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled', __HANDLER__, 'left', 2210__+MAX_llx_menu__, 'accountancy', 'tax_sal', 2200__+MAX_llx_menu__, '/compta/salaries/index.php?leftmenu=tax_salary&mainmenu=accountancy', 'Salaries', 1, 'salaries', '$user->rights->salaries->read', '', 0, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled && $leftmenu=="tax_salary"', __HANDLER__, 'left', 2211__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/salaries/card.php?leftmenu=tax_salary&action=create', 'NewPayment', 2, 'companies', '$user->rights->salaries->write', '', 0, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled && $leftmenu=="tax_salary"', __HANDLER__, 'left', 2212__+MAX_llx_menu__, 'accountancy', '', 2210__+MAX_llx_menu__, '/compta/salaries/index.php?leftmenu=tax_salary', 'Payments', 2, 'companies', '$user->rights->salaries->read', '', 0, 3, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled', __HANDLER__, 'left', 2220__+MAX_llx_menu__, 'accountancy', 'tax_loan', 2200__+MAX_llx_menu__, '/compta/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy', 'Loans', 1, 'loan', '$user->rights->loan->read', '', 0, 1, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2221__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/compta/loan/card.php?leftmenu=tax_loan&action=create', 'NewLoan', 2, 'loan', '$user->rights->loan->write', '', 0, 2, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2222__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/compta/loan/index.php?leftmenu=tax_loan', 'Payments', 2, 'companies', '$user->rights->loan->read', '', 0, 3, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2223__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/compta/loan/calc.php?leftmenu=tax_loan', 'Calculator', 2, 'companies', '$user->rights->loan->calc', '', 0, 4, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled', __HANDLER__, 'left', 2220__+MAX_llx_menu__, 'accountancy', 'tax_loan', 2200__+MAX_llx_menu__, '/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy', 'Loans', 1, 'loan', '$user->rights->loan->read', '', 0, 1, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2221__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/loan/card.php?leftmenu=tax_loan&action=create', 'NewLoan', 2, 'loan', '$user->rights->loan->write', '', 0, 2, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2222__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/loan/index.php?leftmenu=tax_loan', 'Payments', 2, 'companies', '$user->rights->loan->read', '', 0, 3, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->loan->enabled && $leftmenu=="tax_loan"', __HANDLER__, 'left', 2223__+MAX_llx_menu__, 'accountancy', '', 2220__+MAX_llx_menu__, '/loan/calc.php?leftmenu=tax_loan', 'Calculator', 2, 'companies', '$user->rights->loan->calc', '', 0, 4, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled', __HANDLER__, 'left', 2250__+MAX_llx_menu__, 'accountancy', 'tax_social', 2200__+MAX_llx_menu__, '/compta/sociales/index.php?leftmenu=tax_social', 'SocialContributions', 1, '', '$user->rights->tax->charges->lire', '', 0, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled && $leftmenu=="tax_social"', __HANDLER__, 'left', 2251__+MAX_llx_menu__, 'accountancy', '', 2250__+MAX_llx_menu__, '/compta/sociales/charges.php?leftmenu=tax_social&action=create', 'MenuNewSocialContribution', 2, '', '$user->rights->tax->charges->creer', '', 0, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled && $leftmenu=="tax_social"', __HANDLER__, 'left', 2252__+MAX_llx_menu__, 'accountancy', '', 2250__+MAX_llx_menu__, '/compta/charges/index.php?leftmenu=tax_social&mainmenu=accountancy&mode=sconly', 'Payments', 2, '', '$user->rights->tax->charges->lire', '', 0, 3, __ENTITY__); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 13781f0f8b4..0b8e30c746a 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -815,10 +815,10 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if (! empty($conf->loan->enabled)) { $langs->load("loan"); - $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy",$langs->trans("Loans"),1,$user->rights->loan->read, '', $mainmenu, 'tax_loan'); - if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/card.php?leftmenu=tax_loan&action=create",$langs->trans("NewLoan"),2,$user->rights->loan->write); - if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/index.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read); - if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/compta/loan/calc.php?leftmenu=tax_loan",$langs->trans("Calculator"),2,$user->rights->loan->calc); + $newmenu->add("/loan/index.php?leftmenu=tax_loan&mainmenu=accountancy",$langs->trans("Loans"),1,$user->rights->loan->read, '', $mainmenu, 'tax_loan'); + if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/loan/card.php?leftmenu=tax_loan&action=create",$langs->trans("NewLoan"),2,$user->rights->loan->write); + if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/loan/index.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read); + if (empty($leftmenu) || preg_match('/^tax_loan/i',$leftmenu)) $newmenu->add("/loan/calc.php?leftmenu=tax_loan",$langs->trans("Calculator"),2,$user->rights->loan->calc); } // Social contributions diff --git a/htdocs/compta/loan/calc.php b/htdocs/loan/calc.php similarity index 99% rename from htdocs/compta/loan/calc.php rename to htdocs/loan/calc.php index 009c61095c9..0b40ef38f70 100644 --- a/htdocs/compta/loan/calc.php +++ b/htdocs/loan/calc.php @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -require '../../main.inc.php'; +require '../main.inc.php'; $langs->load("loan"); diff --git a/htdocs/compta/loan/card.php b/htdocs/loan/card.php similarity index 94% rename from htdocs/compta/loan/card.php rename to htdocs/loan/card.php index 88a4429e7c5..6a62ffe09ea 100644 --- a/htdocs/compta/loan/card.php +++ b/htdocs/loan/card.php @@ -16,13 +16,13 @@ */ /** - * \file htdocs/compta/loan/card.php + * \file htdocs/loan/card.php * \ingroup loan * \brief Loan card */ -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; @@ -416,7 +416,7 @@ if ($id > 0) $objp = $db->fetch_object($resql); $var=!$var; print "
"; - print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$objp->paiement_type.' '.$objp->num_payment."'.price($objp->amount_insurance)." ".$langs->trans("Currency".$conf->currency)."
'.$langs->trans("Loan").'
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("DateStart").''.dol_print_date($loan->datestart,'day')."
'.$langs->trans("Label").''.$loan->label."
'.$langs->trans("Amount").''.price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).'
Monthly Payment:' . number_format($monthly_payment, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '
(Principal & Interest ONLY)
 '; print '
'; - + $assessed_price = ($sale_price * .85); $residential_yearly_tax = ($assessed_price / 1000) * 14; $residential_monthly_tax = $residential_yearly_tax / 12; - + if ($pmi_per_month) { $pmi_text = "PMI and "; @@ -304,8 +301,8 @@ if ($form_complete && $show_progress) { print '
'; print '
'; - - + + // Set some base variables $principal = $financing_price; $current_month = 1; @@ -315,11 +312,11 @@ if ($form_complete && $show_progress) { $power = -($month_term); $denom = pow((1 + $monthly_interest_rate), $power); $monthly_payment = $principal * ($monthly_interest_rate / (1 - $denom)); - - print "

Amortization For Monthly Payment: " . number_format($monthly_payment, "2", ".", ",") . " over " . $year_term . " years
\n"); - + + print "

Amortization For Monthly Payment: " . number_format($monthly_payment, "2", ".", ",") . " over " . $year_term . " years
\n"; + print ''; - + // This LEGEND will get reprinted every 12 months $legend = ''; $legend.= ''; @@ -327,7 +324,7 @@ if ($form_complete && $show_progress) { $legend.= ''; $legend.= ''; $legend.= ''; - + print $legend; // Loop through and get the current month's payments for @@ -348,14 +345,14 @@ if ($form_complete && $show_progress) { print ''; print ''; print ''; - + ($current_month % 12) ? $show_legend = FALSE : $show_legend = TRUE; if ($show_legend) { print ''; print ''; print ''; - + $total_spent_this_year = $this_year_interest_paid + $this_year_principal_paid; print ''; print ''; @@ -369,11 +366,11 @@ if ($form_complete && $show_progress) { print ''; print ''; print ''; - + $current_year++; $this_year_interest_paid = 0; $this_year_principal_paid = 0; - + if (($current_month + 6) < $month_term) { echo $legend; diff --git a/htdocs/loan/class/loan.class.php b/htdocs/loan/class/loan.class.php index d1b770f744c..9ab8a690494 100644 --- a/htdocs/loan/class/loan.class.php +++ b/htdocs/loan/class/loan.class.php @@ -69,7 +69,7 @@ class Loan extends CommonObject * Load object in memory from database * * @param int $id id object - * @return void + * @return int <0 error , >=0 no error */ function fetch($id) { @@ -146,8 +146,8 @@ class Loan extends CommonObject if (($conf->accounting->enabled) && empty($this->account_capital) && empty($this->account_insurance) && empty($this->account_interest)) { $this->error="ErrorAccountingParameter"; - return -2; - } + return -2; + } $this->db->begin(); @@ -304,8 +304,12 @@ class Loan extends CommonObject $sql.= " paid = 1"; $sql.= " WHERE rowid = ".$this->id; $return = $this->db->query($sql); - if ($return) return 1; - else return -1; + if ($return) { + return 1; + } else { + $this->error=$this->db->lasterror(); + return -1; + } } /** @@ -423,7 +427,8 @@ class Loan extends CommonObject } else { - return -1; + $this->error=$this->db->lasterror(); + return -1; } } @@ -464,12 +469,19 @@ class Loan extends CommonObject $this->date_creation = $this->db->jdate($obj->datec); if (empty($obj->fk_user_modif)) $obj->tms = ""; $this->date_modification = $this->db->jdate($obj->tms); + + return 1; + } + else + { + return 0; } $this->db->free($result); } else { - dol_print_error($this->db); + $this->error=$this->db->lasterror(); + return -1; } } } \ No newline at end of file diff --git a/htdocs/loan/index.php b/htdocs/loan/index.php index db6e9544cee..082e5d0d0c2 100644 --- a/htdocs/loan/index.php +++ b/htdocs/loan/index.php @@ -50,7 +50,8 @@ $search_label=GETPOST('search_label','alpha'); $search_amount=GETPOST('search_amount','alpha'); $filtre=GETPOST("filtre"); -if (GETPOST("button_removefilter")) +// Purge search criteria +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { $search_ref=""; $search_label=""; @@ -112,11 +113,11 @@ if ($resql) print ''; print ''; print ''; - + while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); - + $var = !$var; print ""; @@ -135,7 +136,7 @@ if ($resql) print ''; print "\n"; - + $i++; } @@ -147,6 +148,6 @@ else { dol_print_error($db); } -$db->close(); - llxFooter(); + +$db->close(); \ No newline at end of file diff --git a/htdocs/loan/info.php b/htdocs/loan/info.php index 5e90474642a..16c349b92e9 100644 --- a/htdocs/loan/info.php +++ b/htdocs/loan/info.php @@ -46,20 +46,25 @@ $result = restrictedArea($user, 'loan', $id, '',''); $help_url='EN:Module_Loan|FR:Module_Emprunt'; llxHeader("",$langs->trans("Loan"),$help_url); -$loan = new Loan($db); -$loan->fetch($id); -$loan->info($id); +if ($id > 0) { + $loan = new Loan($db); + $loan->fetch($id); + $loan->info($id); -$head = loan_prepare_head($loan); + $head = loan_prepare_head($loan); -dol_fiche_head($head, 'info', $langs->trans("Loan"), 0, 'bill'); + dol_fiche_head($head, 'info', $langs->trans("Loan"), 0, 'bill'); + print '
' . $langs->trans("Month") . '' . $langs->trans("Capital") . '' . $langs->trans("Position") . '
' . number_format($principal_paid, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '' . number_format($remaining_balance, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '
' . $langs->trans("Totalsforyear") . ' ' . $current_year . '
 
 
'.$loan_static->LibStatut($obj->paid,5,$obj->alreadypayed).'
'; + dol_print_object_info($loan); + print '
'; -print '
'; -dol_print_object_info($loan); -print '
'; - -print '
'; + print '
'; +} +else +{ + // $id ? +} llxFooter(); diff --git a/htdocs/loan/payment/card.php b/htdocs/loan/payment/card.php index 901daffaa2d..f75a2244154 100644 --- a/htdocs/loan/payment/card.php +++ b/htdocs/loan/payment/card.php @@ -133,7 +133,6 @@ dol_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), 0, 'payment'); if ($action == 'delete') { print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); - } /* @@ -142,8 +141,7 @@ if ($action == 'delete') if ($action == 'valide') { $facid = $_GET['facid']; - print $form->formconfirm('card.php?id='.$payment->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); - + print $form->formconfirm('card.php?id='.$payment->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); } @@ -283,18 +281,15 @@ if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) } */ -if ($_GET['action'] == '') +if (empty($action) && ! empty($user->rights->loan->delete)) { - if ($user->rights->loan->delete) + if (! $disable_delete) { - if (! $disable_delete) - { - print ''.$langs->trans('Delete').''; - } - else - { - print ''.$langs->trans('Delete').''; - } + print ''.$langs->trans('Delete').''; + } + else + { + print ''.$langs->trans('Delete').''; } } From 5617fb14b26e0ded136cf88eb2f3bf822fa71871 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 23 Mar 2015 09:52:05 +0100 Subject: [PATCH 23/24] fix skeletton --- dev/skeletons/skeleton_class.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/skeletons/skeleton_class.class.php b/dev/skeletons/skeleton_class.class.php index c59b3986a08..ff0c2f61200 100644 --- a/dev/skeletons/skeleton_class.class.php +++ b/dev/skeletons/skeleton_class.class.php @@ -221,7 +221,7 @@ class Skeleton_Class extends CommonObject $line->prop1 = $obj->field1; $line->prop2 = $obj->field2; - $this->line[]=$line; + $this->lines[]=$line; //... } $this->db->free($resql); From c6ad35e00185375d53d84c7e8b39d45f0af36513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Mon, 23 Mar 2015 13:40:55 +0100 Subject: [PATCH 24/24] Implemented statuses submenu for List menu of supplier and customer invoices. Menu "Pending payment" has been moved to the "List" submenu. --- htdocs/core/menus/standard/eldy.lib.php | 18 ++++++++++++++++-- htdocs/fourn/facture/list.php | 7 +++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 7c6ef944f7c..cc97470a310 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -3,6 +3,7 @@ * Copyright (C) 2010 Regis Houssin * Copyright (C) 2012-2014 Juanjo Menent * Copyright (C) 2013 Cédric Salvador + * Copyright (C) 2015 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -738,8 +739,14 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills",$langs->trans("BillsCustomers"),0,$user->rights->facture->lire, '', $mainmenu, 'customers_bills'); $newmenu->add("/compta/facture.php?action=create&leftmenu=customers_bills",$langs->trans("NewBill"),1,$user->rights->facture->creer); $newmenu->add("/compta/facture/fiche-rec.php?leftmenu=customers_bills",$langs->trans("Repeatables"),1,$user->rights->facture->lire); + $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills",$langs->trans("List"),1,$user->rights->facture->lire); - $newmenu->add("/compta/facture/impayees.php?leftmenu=customers_bills",$langs->trans("Unpaid"),1,$user->rights->facture->lire); + if (empty($leftmenu) || ($leftmenu == 'customers_bills')) { + $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills&search_status=0",$langs->trans("BillShortStatusDraft"),2,$user->rights->facture->lire); + $newmenu->add("/compta/facture/impayees.php?leftmenu=customers_bills",$langs->trans("BillShortStatusNotPaid"),2,$user->rights->facture->lire); + $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills&search_status=2",$langs->trans("BillShortStatusPaid"),2,$user->rights->facture->lire); + $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills&search_status=3",$langs->trans("BillShortStatusCanceled"),2,$user->rights->facture->lire); + } $newmenu->add("/compta/paiement/list.php?leftmenu=customers_bills_payments",$langs->trans("Payments"),1,$user->rights->facture->lire); @@ -758,7 +765,14 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $langs->load("bills"); $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills", $langs->trans("BillsSuppliers"),0,$user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills'); $newmenu->add("/fourn/facture/card.php?action=create",$langs->trans("NewBill"),1,$user->rights->fournisseur->facture->creer); - $newmenu->add("/fourn/facture/impayees.php", $langs->trans("Unpaid"),1,$user->rights->fournisseur->facture->lire); + $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills", $langs->trans("List"),1,$user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills'); + + if (empty($leftmenu) || ($leftmenu == 'suppliers_bills')) { + $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills&search_status=0", $langs->trans("BillShortStatusDraft"),2,$user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills'); + $newmenu->add("/fourn/facture/impayees.php", $langs->trans("BillShortStatusNotPaid"),2,$user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills'); + $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills&search_status=2", $langs->trans("BillShortStatusPaid"),2,$user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills'); + } + $newmenu->add("/fourn/facture/paiement.php", $langs->trans("Payments"),1,$user->rights->fournisseur->facture->lire); $newmenu->add("/compta/facture/stats/index.php?leftmenu=suppliers_bills&mode=supplier", $langs->trans("Statistics"),1,$user->rights->fournisseur->facture->lire); diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index 66ad20e4c05..3c1b0f06cb6 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -5,6 +5,7 @@ * Copyright (C) 2013 Philippe Grand * Copyright (C) 2013 Florian Henry * Copyright (C) 2013 Cédric Salvador + * Copyright (C) 2015 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -70,6 +71,7 @@ $search_label = GETPOST("search_label","alpha"); $search_company = GETPOST("search_company","alpha"); $search_amount_no_tax = GETPOST("search_amount_no_tax","alpha"); $search_amount_all_tax = GETPOST("search_amount_all_tax","alpha"); +$search_status=GETPOST('search_status','alpha'); $month = GETPOST("month","int"); $year = GETPOST("year","int"); $filter = GETPOST("filtre"); @@ -188,6 +190,11 @@ if ($search_amount_all_tax != '') $sql .= natural_search('fac.total_ttc', $search_amount_all_tax, 1); } +if ($search_status != '') +{ + $sql.= " AND fac.fk_statut = '".$db->escape($search_status)."'"; +} + $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {