Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2013-01-12 19:59:09 +01:00
commit 980bfde83e
10 changed files with 327 additions and 117 deletions

View File

@ -5,7 +5,7 @@
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -1804,7 +1804,7 @@ if ($action == 'create')
print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>';
// Factures predefinies
if (empty($origin) && empty($originid))
if (empty($origin) && empty($originid) && $socid)
{
$sql = 'SELECT r.rowid, r.titre, r.total_ttc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_rec as r';
@ -1834,16 +1834,27 @@ if ($action == 'create')
$db->free($resql);
}
else
{
{
dol_print_error($db);
}
}
// Tiers
print '<tr><td class="fieldrequired">'.$langs->trans('Customer').'</td><td colspan="2">';
print $soc->getNomUrl(1);
print '<input type="hidden" name="socid" value="'.$soc->id.'">';
print '</td>';
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans('Customer').'</td>';
if($socid)
{
print '<td colspan="2">';
print $soc->getNomUrl(1);
print '<input type="hidden" name="socid" value="'.$soc->id.'">';
print '</td>';
}
else
{
print '<td colspan="2">';
print $form->select_company('','socid','s.client = 1',1);
print '</td>';
}
print '</tr>'."\n";
// Type de facture
@ -1916,72 +1927,77 @@ if ($action == 'create')
print $desc;
print '</td></tr>'."\n";
}
// Replacement
print '<tr height="18"><td valign="middle">';
print '<input type="radio" name="type" value="1"'.(GETPOST('type')==1?' checked="checked"':'');
if (! $options) print ' disabled="disabled"';
print '>';
print '</td><td valign="middle">';
$text=$langs->trans("InvoiceReplacementAsk").' ';
$text.='<select class="flat" name="fac_replacement" id="fac_replacement"';
if (! $options) $text.=' disabled="disabled"';
$text.='>';
if ($options)
{
$text.='<option value="-1"></option>';
$text.=$options;
}
else
{
$text.='<option value="-1">'.$langs->trans("NoReplacableInvoice").'</option>';
}
$text.='</select>';
$desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1);
print $desc;
print '</td></tr>'."\n";
// Credit note
print '<tr height="18"><td valign="middle">';
print '<input type="radio" name="type" value="2"'.(GETPOST('type')==2?' checked=true':'');
if (! $optionsav) print ' disabled="disabled"';
print '>';
print '</td><td valign="middle">';
$text=$langs->transnoentities("InvoiceAvoirAsk").' ';
// $text.='<input type="text" value="">';
$text.='<select class="flat" name="fac_avoir" id="fac_avoir"';
if (! $optionsav) $text.=' disabled="disabled"';
$text.='>';
if ($optionsav)
{
$text.='<option value="-1"></option>';
$text.=$optionsav;
}
else
{
$text.='<option value="-1">'.$langs->trans("NoInvoiceToCorrect").'</option>';
}
$text.='</select>';
$desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1);
print $desc;
print '</td></tr>'."\n";
print '</table>';
print '</td></tr>';
// Discounts for third party
print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="2">';
if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$soc->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">'.$soc->remise_client.'</a>');
else print $langs->trans("CompanyHasNoRelativeDiscount");
print ' <a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$soc->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">('.$langs->trans("EditRelativeDiscount").')</a>';
print '. ';
print '<br>';
if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",'<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$soc->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">'.price($absolute_discount).'</a>',$langs->trans("Currency".$conf->currency));
else print $langs->trans("CompanyHasNoAbsoluteDiscount");
print ' <a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$soc->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">('.$langs->trans("EditGlobalDiscounts").')</a>';
print '.';
print '</td></tr>';
if ($socid)
{
// Replacement
print '<tr height="18"><td valign="middle">';
print '<input type="radio" name="type" value="1"'.(GETPOST('type')==1?' checked="checked"':'');
if (! $options) print ' disabled="disabled"';
print '>';
print '</td><td valign="middle">';
$text=$langs->trans("InvoiceReplacementAsk").' ';
$text.='<select class="flat" name="fac_replacement" id="fac_replacement"';
if (! $options) $text.=' disabled="disabled"';
$text.='>';
if ($options)
{
$text.='<option value="-1"></option>';
$text.=$options;
}
else
{
$text.='<option value="-1">'.$langs->trans("NoReplacableInvoice").'</option>';
}
$text.='</select>';
$desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1);
print $desc;
print '</td></tr>'."\n";
// Credit note
print '<tr height="18"><td valign="middle">';
print '<input type="radio" name="type" value="2"'.(GETPOST('type')==2?' checked=true':'');
if (! $optionsav) print ' disabled="disabled"';
print '>';
print '</td><td valign="middle">';
$text=$langs->transnoentities("InvoiceAvoirAsk").' ';
// $text.='<input type="text" value="">';
$text.='<select class="flat" name="fac_avoir" id="fac_avoir"';
if (! $optionsav) $text.=' disabled="disabled"';
$text.='>';
if ($optionsav)
{
$text.='<option value="-1"></option>';
$text.=$optionsav;
}
else
{
$text.='<option value="-1">'.$langs->trans("NoInvoiceToCorrect").'</option>';
}
$text.='</select>';
$desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1);
print $desc;
print '</td></tr>'."\n";
}
print '</table>';
print '</td></tr>';
if($socid)
{
// Discounts for third party
print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="2">';
if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$soc->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">'.$soc->remise_client.'</a>');
else print $langs->trans("CompanyHasNoRelativeDiscount");
print ' <a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$soc->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">('.$langs->trans("EditRelativeDiscount").')</a>';
print '. ';
print '<br>';
if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",'<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$soc->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">'.price($absolute_discount).'</a>',$langs->trans("Currency".$conf->currency));
else print $langs->trans("CompanyHasNoAbsoluteDiscount");
print ' <a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$soc->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid')).'">('.$langs->trans("EditGlobalDiscounts").')</a>';
print '.';
print '</td></tr>';
}
// Date invoice
print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td colspan="2">';
$form->select_date($dateinvoice,'','','','',"add",1,1);
@ -1998,7 +2014,7 @@ if ($action == 'create')
print '</td></tr>';
// Project
if (! empty($conf->projet->enabled))
if (! empty($conf->projet->enabled) && $socid)
{
$langs->load('projects');
print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';

View File

@ -52,7 +52,8 @@ class ExtraFields
'int'=>'Int',
'double'=>'Float',
'date'=>'Date',
'datetime'=>'DateAndTime'
'datetime'=>'DateAndTime',
'boolean'=>'Boolean'
);
/**
@ -135,7 +136,14 @@ class ExtraFields
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
{
$field_desc = array('type'=>$type, 'value'=>$length, 'null'=>($required?'NOT NULL':'NULL'));
if ($type=='boolean') {
$typedb='int';
$lengthdb='1';
} else {
$typedb=$type;
$lengthdb=$length;
}
$field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL'));
$result=$this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
if ($result > 0)
{
@ -304,7 +312,14 @@ class ExtraFields
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
{
$field_desc = array('type'=>$type, 'value'=>$length, 'null'=>($required?'NOT NULL':'NULL'));
if ($type=='boolean') {
$typedb='int';
$lengthdb='1';
} else {
$typedb=$type;
$lengthdb=$length;
}
$field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL'));
$result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
if ($result > 0)
{
@ -487,7 +502,7 @@ class ExtraFields
function showInputField($key,$value,$moreparam='')
{
global $conf;
$label=$this->attribute_label[$key];
$type =$this->attribute_type[$key];
$size =$this->attribute_size[$key];
@ -534,6 +549,16 @@ class ExtraFields
$doleditor=new DolEditor('options_'.$key,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,5,100);
$out=$doleditor->Create(1);
}
else if ($type == 'boolean')
{
$checked='';
if (!empty($value)) {
$checked=' checked="checked" value="1" ';
} else {
$checked=' value="1" ';
}
$out='<input type="checkbox" name="options_'.$key.'" '.$checked.' '.($moreparam?$moreparam:'').'>';
}
// Add comments
if ($type == 'date') $out.=' (YYYY-MM-DD)';
elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)';
@ -550,6 +575,7 @@ class ExtraFields
*/
function showOutputField($key,$value,$moreparam='')
{
$label=$this->attribute_label[$key];
$type=$this->attribute_type[$key];
$size=$this->attribute_size[$key];
@ -568,6 +594,14 @@ class ExtraFields
{
$showsize=10;
}
elseif ($type == 'boolean')
{
$checked='';
if (!empty($value)) {
$checked=' checked="checked" ';
}
$value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly="readonly">';
}
else
{
$showsize=round($size);

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012-2013 Juanjo Menent <jmenent@2byte.es>
*
* 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
@ -913,7 +913,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after)
$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills",$langs->trans("BillsCustomers"),0,$user->rights->facture->lire, '', $mainmenu, 'customers_bills');
if (empty($user->societe_id))
{
$newmenu->add("/compta/clients.php?action=facturer&amp;leftmenu=customers_bills",$langs->trans("NewBill"),1,$user->rights->facture->creer);
$newmenu->add("/compta/facture.php?action=create&amp;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);

View File

@ -29,6 +29,7 @@
else if (type == 'int') { size.val('10').removeAttr('disabled'); }
else if (type == 'text') { size.val('2000').removeAttr('disabled'); }
else if (type == 'varchar') { size.val('255').removeAttr('disabled'); }
else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');}
else size.val('').attr('disabled','disabled');
}
init_typeoffields();

View File

@ -31,6 +31,7 @@
else if (type == 'int') { size.val('10').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); }
else if (type == 'text') { size.val('2000').removeAttr('disabled'); unique.attr('disabled','disabled').removeAttr('checked'); }
else if (type == 'varchar') { size.val('255').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); }
else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');}
else size.val('').attr('disabled','disabled');
}
init_typeoffields('');

View File

@ -31,6 +31,7 @@
else if (type == 'int') { size.removeAttr('disabled'); }
else if (type == 'text') { size.removeAttr('disabled'); unique.attr('disabled','disabled').removeAttr('checked'); }
else if (type == 'varchar') { size.removeAttr('disabled'); }
else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled');}
else size.val('').attr('disabled','disabled');
}
init_typeoffields(jQuery("#type").val());

View File

@ -351,6 +351,7 @@ Int=Integer
Float=Float
DateAndTime=Date and hour
Unique=Unique
Boolean=Boolean (Checkbox)
LibraryToBuildPDF=Library used to build PDF
WarningUsingFPDF=Warning: Your <b>conf.php</b> contains directive <b>dolibarr_pdf_force_fpdf=1</b>. This means you use the FPDF library to generate PDF files. This library is old and does not support a lot of features (Unicode, image transparency, cyrillic, arab and asiatic languages, ...), so you may experience errors during PDF generation.<br>To solve this and have a full support of PDF generation, please download <a href="http://www.tcpdf.org/" target="_blank">TCPDF library</a>, then comment or remove the line <b>$dolibarr_pdf_force_fpdf=1</b>, and add instead <b>$dolibarr_lib_TCPDF_PATH='path_to_TCPDF_dir'</b>
LocalTaxDesc=Some countries apply 2 or 3 taxes on each invoice line. If this is the case, choose type for second and third tax and its rate. Possible type are:<br>1 : local tax apply on products and services without vat (vat is not applied on local tax)<br>2 : local tax apply on products and services before vat (vat is calculated on amount + localtax)<br>3 : local tax apply on products without vat (vat is not applied on local tax)<br>4 : local tax apply on products before vat (vat is calculated on amount + localtax)<br>5 : local tax apply on services without vat (vat is not applied on local tax)<br>6 : local tax apply on services before vat (vat is calculated on amount + localtax)

View File

@ -346,6 +346,7 @@ TextLong=Texte long
Int=Numérique entier
Float=Décimal
DateAndTime=Date et heure
Boolean=Booleen (Checkbox)
LibraryToBuildPDF=Bibliothèque utilisée pour la génération des PDF
WarningUsingFPDF=Attention: Votre fichier <b>conf.php</b> contient la directive <b>dolibarr_pdf_force_fpdf=1</b>. Cela signifie que vous utilisez la librairie FPDF pour générer vos fichiers PDF. Cette librairie est ancienne et ne couvre pas de nombreuses fonctionnalitée (Unicode, transparence des images, langues cyrillic, arabes ou asiatiques...), aussi vous pouvez rencontrez des problèmes durant la génération des PDF.<br>Pour résoudre cela et avoir un support complet de PDF, vous pouvez télécharger la <a href="http://www.tcpdf.org/" target="_blank">librairie TCPDF</a> puis commenter ou supprimer la ligne <b>$dolibarr_pdf_force_fpdf=1</b>, et ajouter à la place <b>$dolibarr_lib_TCPDF_PATH='chemin_vers_TCPDF'</b>
LocalTaxDesc=Certains pays appliquent 2 voir 3 taux sur chaque ligne de facture. Si c'est le cas, choisissez le type du deuxième et troisième taux et sa valeur. Les types possibles sont:<br>1 : taxe locale sur les produits et services hors tva (la tva n'est pas appliquée sur la taxe locale)<br>2 : taxe locale sur les produits et services avant tva (la tva est appliquée sur le montant + la taxe locale)<br>3 : taxe locale uniquement sur les produits hors tva (la tva n'est pas appliquée sur la taxe locale)<br>4 : taxe locale uniquement sur les produits avant tva (la tva est appliquée sur le montant + la taxe locale)<br>5 : taxe locale uniquement sur les services hors tva (la tva n'est pas appliquée sur la taxe locale)<br>6 : taxe locale uniquement sur les service avant tva (la tva est appliquée sur le montant + la taxe locale)

View File

@ -980,6 +980,8 @@ class User extends CommonObject
$this->lastname = $member->lastname;
$this->firstname = $member->firstname;
$this->email = $member->email;
$this->fk_member = $member->id;
if ($member->fk_soc) $sql.= ", fk_societe=".$member->fk_soc;
$this->pass = $member->pass;
if (empty($login)) $login=strtolower(substr($member->firstname, 0, 4)) . strtolower(substr($member->lastname, 0, 4));
@ -992,26 +994,26 @@ class User extends CommonObject
if ($result > 0)
{
$result=$this->setPassword($user,$this->pass);
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql.= " SET fk_member=".$member->id;
if ($member->fk_soc) $sql.= ", fk_societe=".$member->fk_soc;
$sql.= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::create_from_member sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$this->db->commit();
return $this->id;
}
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::create_from_member - 1 - ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
if ($member->fk_soc) {
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql.= " SET fk_societe=".$member->fk_soc;
$sql.= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::create_from_member sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$this->db->commit();
return $this->id;
}
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::create_from_member - 1 - ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
}
}
else

View File

@ -139,7 +139,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase
/**
* testAdherentFetch
*
* @param int $id Id of object to fecth
* @param int $id Id of object to fetch
* @return object Fetched object
*
* @depends testAdherentCreate
@ -161,13 +161,38 @@ class AdherentTest extends PHPUnit_Framework_TestCase
return $localobject;
}
/**
* testAdherentFetchLogin
*
* @param Adherent $localobject Member instance
* @return Adherent
*
* @depends testAdherentFetch
* The depends says test is run only if previous is ok
*/
public function testAdherentFetchLogin(Adherent $localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$newobject = new Adherent($this->savdb);
$result = $newobject->fetch_login($localobject->login);
$this->assertEquals($newobject, $localobject);
return $localobject;
}
/**
* testAdherentUpdate
*
* @param Adherent $localobject Member instance
* @return Adherent
*
* @depends testAdherentFetch
* @depends testAdherentFetchLogin
* The depends says test is run only if previous is ok
*/
public function testAdherentUpdate(Adherent $localobject)
@ -225,6 +250,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase
$this->assertEquals($localobject->town, $newobject->town);
$this->assertEquals($localobject->country_id, $newobject->country_id);
$this->assertEquals('BE', $newobject->country_code);
$this->assertEquals('Belgium', $newobject->country);
$this->assertEquals($localobject->statut, $newobject->statut);
$this->assertEquals($localobject->phone, $newobject->phone);
$this->assertEquals($localobject->phone_perso, $newobject->phone_perso);
@ -233,7 +259,8 @@ class AdherentTest extends PHPUnit_Framework_TestCase
$this->assertEquals($localobject->naiss, $timestamp);
$this->assertEquals($localobject->morphy, $newobject->morphy);
return $localobject;
//We return newobject because of new values
return $newobject;
}
/**
@ -257,9 +284,9 @@ class AdherentTest extends PHPUnit_Framework_TestCase
'%ADDRESS%,%ZIP%,%TOWN%,%COUNTRY%,%EMAIL%,%NAISS%,%PHOTO%,%LOGIN%,%PASSWORD%,%PRENOM%,'.
'%NOM%,%SOCIETE%,%ADRESSE%,%CP%,%VILLE%,%PAYS%';
$expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',0,New firstname,New name,New firstname New name,'.
'New company,New address,New zip,New town,,newemail@newemail.com,'.dol_print_date($localobject->naiss,'day').',,'.
'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,';
$expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',,New firstname,New name,New firstname New name,'.
'New company,New address,New zip,New town,Belgium,newemail@newemail.com,'.dol_print_date($localobject->naiss,'day').',,'.
'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,Belgium';
$result = $localobject->makeSubstitution($template);
print __METHOD__." result=".$result."\n";
@ -268,16 +295,107 @@ class AdherentTest extends PHPUnit_Framework_TestCase
return $localobject;
}
/**
* testAdherentSetUserId
*
* @param Adherent $localobject Member instance
* @return Adherent
*
* @depends testAdherentMakeSubstitution
* The depends says test is run only if previous is ok
*/
public function testAdherentSetUserId(Adherent $localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
//We associate member with user
$result = $localobject->setUserId($user->id);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertEquals($result, 1);
//We update user object
$user->fetch($user->id);
print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n";
$this->assertEquals($user->fk_member, $localobject->id);
//We remove association with user
$result = $localobject->setUserId(0);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertEquals($result, 1);
//We update user object
$user->fetch($user->id);
print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n";
$this->assertNull($user->fk_member);
return $localobject;
}
/**
* testAdherentSetThirdPartyId
*
* @param Adherent $localobject Member instance
* @return Adherent
*
* @depends testAdherentSetUserId
* The depends says test is run only if previous is ok
*/
public function testAdherentSetThirdPartyId(Adherent $localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
//Create a Third Party
$thirdparty = new Societe($db);
$thirdparty->initAsSpecimen();
$result = $thirdparty->create($user);
print __METHOD__." id=".$localobject->id." third party id=".$thirdparty->id." result=".$result."\n";
$this->assertTrue($result > 0);
//Set Third Party ID
$result = $localobject->setThirdPartyId($thirdparty->id);
$this->assertEquals($result, 1);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
//Adherent is updated with new data
$localobject->fetch($localobject->id);
$this->assertEquals($localobject->fk_soc, $thirdparty->id);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
//We remove the third party association
$result = $localobject->setThirdPartyId(0);
$this->assertEquals($result, 1);
//And check if it has been updated
$localobject->fetch($localobject->id);
$this->assertNull($localobject->fk_soc);
//Now we remove the third party
$result = $thirdparty->delete($thirdparty->id);
$this->assertEquals($result, 1);
return $localobject;
}
/**
* testAdherentValid
*
* @param Adherent $localobject Member instance
* @return Adherent
*
* @depends testAdherentMakeSubstitution
* @depends testAdherentSetThirdPartyId
* The depends says test is run only if previous is ok
*/
public function testAdherentValid(Adherent $localobject)
public function testAdherentValidate(Adherent $localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
@ -298,7 +416,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase
* @param Adherent $localobject Member instance
* @return int Id of object
*
* @depends testAdherentValid
* @depends testAdherentValidate
* The depends says test is run only if previous is ok
*/
public function testAdherentOther(Adherent $localobject)
@ -318,19 +436,56 @@ class AdherentTest extends PHPUnit_Framework_TestCase
print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
$this->assertNotEquals($localobject->date_creation, '');
return $localobject->id;
return $localobject;
}
/**
* testAdherentResiliate
*
* @param Adherent $localobject Member instance
* @return Adherent
*
* @depends testAdherentOther
* The depends says test is run only if previous is ok
*/
public function testAdherentResiliate(Adherent $localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
//Let's resilie un adherent
$result = $localobject->resiliate($user);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertEquals($result, 1);
//Is statut updated?
$this->assertEquals($localobject->statut, 0);
//We update the object and let's check if it was updated on DB
$localobject->fetch($localobject->id);
$this->assertEquals($localobject->statut, 0);
//Now that status=0, resiliate should return 0
$result = $localobject->resiliate($user);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertEquals($result, 0);
return $localobject;
}
/**
* testAdherentDelete
*
* @param int $id Id of object to delete
* @param Adherent $localobject Member instance
* @return void
*
* @depends testAdherentOther
* @depends testAdherentResiliate
* The depends says test is run only if previous is ok
*/
public function testAdherentDelete($id)
public function testAdherentDelete($localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
@ -338,10 +493,8 @@ class AdherentTest extends PHPUnit_Framework_TestCase
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Adherent($this->savdb);
$result=$localobject->fetch($id);
$result=$localobject->delete($id);
print __METHOD__." id=".$id." result=".$result."\n";
$result=$localobject->delete($localobject->id);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $result;