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 '';