From 1409c8f4503c7f527f7faf538d7031bbbfdc6adc Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 21 Sep 2014 21:38:33 +0200 Subject: [PATCH] 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