From d3252d1348cb736fe4cd4e809f313f9f30f76d82 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 29 Sep 2014 20:37:51 +0200 Subject: [PATCH] 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),