From bbb1db7a5172c06bb0411e4d006d7a24ffd4c095 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 7 Sep 2010 01:32:20 +0000 Subject: [PATCH] Work on invoice creation when creating subscription --- htdocs/adherents/card_subscriptions.php | 177 +++++++++++++++++- htdocs/adherents/fiche.php | 62 ++---- htdocs/compta/facture/class/facture.class.php | 1 + htdocs/core/class/html.form.class.php | 4 +- 4 files changed, 187 insertions(+), 57 deletions(-) diff --git a/htdocs/adherents/card_subscriptions.php b/htdocs/adherents/card_subscriptions.php index b3a159046b3..d1787ad7ae7 100644 --- a/htdocs/adherents/card_subscriptions.php +++ b/htdocs/adherents/card_subscriptions.php @@ -39,6 +39,17 @@ $langs->load("members"); $langs->load("users"); $langs->load("mails"); +// If socid provided by ajax company selector +if (! empty($_REQUEST['socid_id'])) +{ + $_GET['socid'] = $_GET['socid_id']; + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + +// Security check +if (! $user->rights->adherent->cotisation->lire) accessforbidden(); + $adh = new Adherent($db); $adho = new AdherentOptions($db); $adht = new AdherentType($db); @@ -51,14 +62,103 @@ $action=GETPOST('action'); $rowid=GETPOST('rowid'); $typeid=GETPOST('typeid'); -if (! $user->rights->adherent->cotisation->lire) -accessforbidden(); +if ($rowid) +{ + // Load member + $result = $adh->fetch($rowid); + + // Define variables to know what current user can do on users + $canadduser=($user->admin || $user->rights->user->user->creer); + // Define variables to know what current user can do on properties of user linked to edited member + if ($adh->user_id) + { + // $user est le user qui edite, $adh->user_id est l'id de l'utilisateur lies au membre edite + $caneditfielduser=( (($user->id == $adh->user_id) && $user->rights->user->self->creer) + || (($user->id != $adh->user_id) && $user->rights->user->user->creer) ); + $caneditpassworduser=( (($user->id == $adh->user_id) && $user->rights->user->self->password) + || (($user->id != $adh->user_id) && $user->rights->user->user->password) ); + } +} + +// Define variables to know what current user can do on members +$canaddmember=$user->rights->adherent->creer; +// Define variables to know what current user can do on properties of a member +if ($rowid) +{ + $caneditfieldmember=$user->rights->adherent->creer; +} + +// Define size of logo small and mini (might be set into other pages) +$maxwidthsmall=270;$maxheightsmall=150; +$maxwidthmini=128;$maxheightmini=72; +$quality = 80; + /* * Actions */ + +if ($_POST['action'] == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer)) +{ + $error=0; + if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only + { + if ($_POST["userid"] != $user->id && $_POST["userid"] != $adh->user_id) + { + $error++; + $mesg='
'.$langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly").'
'; + } + } + + if (! $error) + { + if ($_POST["userid"] != $adh->user_id) // If link differs from currently in database + { + $result=$adh->setUserId($_POST["userid"]); + if ($result < 0) dol_print_error($adh->db,$adh->error); + $_POST['action']=''; + $action=''; + } + } +} + +if ($_POST['action'] == 'setsocid') +{ + $error=0; + if (! $error) + { + if (GETPOST("socid") != $adh->fk_soc) // If link differs from currently in database + { + $sql ="SELECT rowid FROM ".MAIN_DB_PREFIX."adherent"; + $sql.=" WHERE fk_soc = '".GETPOST("socid")."'"; + $resql = $db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj && $obj->rowid > 0) + { + $othermember=new Adherent($db); + $othermember->fetch($obj->rowid); + $thirdparty=new Societe($db); + $thirdparty->fetch(GETPOST("socid")); + $error++; + $mesg='
'.$langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty",$othermember->getFullName($langs),$othermember->login,$thirdparty->nom).'
'; + } + } + + if (! $error) + { + $result=$adh->setThirdPartyId(GETPOST("socid")); + if ($result < 0) dol_print_error($adh->db,$adh->error); + $_POST['action']=''; + $action=''; + } + } + } +} + if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisation' && ! $_POST["cancel"]) { $error=0; @@ -240,6 +340,7 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio } + /* * View */ @@ -250,7 +351,6 @@ llxHeader('',$langs->trans("Subscriptions"),'EN:Module_Foundations|FR:Module_Adh if ($rowid) { - $adh->id = $rowid; $result=$adh->fetch($rowid); $result=$adh->fetch_optionals($rowid); @@ -264,8 +364,9 @@ if ($rowid) dol_fiche_head($head, 'subscription', $langs->trans("Member"), 0, 'user'); - print '
'; + print ''; print ''; + print ''; print ''; // Ref @@ -292,7 +393,6 @@ if ($rowid) print ''; // Date end subscription - // Date fin cotisation print ''; + // Third party Dolibarr + if ($conf->societe->enabled) + { + print ''; + } + + // Login Dolibarr + print ''; + print "
'.$langs->trans("Status").''.$adh->getLibStatut(4).'
'.$langs->trans("SubscriptionEndDate").''; if ($adh->datefin) { @@ -313,6 +413,73 @@ if ($rowid) } print '
'; + print ''; + if ($_GET['action'] != 'editthirdparty' && $user->rights->adherent->creer) print ''; + print '
'; + print $langs->trans("LinkedToDolibarrThirdParty"); + print 'id.'">'.img_edit($langs->trans('SetLinkToThirdParty'),1).'
'; + print '
'; + if ($_GET['action'] == 'editthirdparty') + { + $htmlname='socid'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + print $html->select_societes($adh->fk_soc,'socid','',1); + print '
'; + } + else + { + if ($adh->fk_soc) + { + $company=new Societe($db); + $result=$company->fetch($adh->fk_soc); + print $company->getNomUrl(1); + } + else + { + print $langs->trans("NoThirdPartyAssociatedToMember"); + } + } + print '
'; + print ''; + if ($_GET['action'] != 'editlogin' && $user->rights->adherent->creer) print ''; + print '
'; + print $langs->trans("LinkedToDolibarrUser"); + print 'id.'">'.img_edit($langs->trans('SetLinkToUser'),1).'
'; + print '
'; + if ($_GET['action'] == 'editlogin') + { + /*$include=array(); + if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only + { + $include=array($adh->user_id,$user->id); + }*/ + print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$adh->id,$adh->user_id,'userid',''); + } + else + { + if ($adh->user_id) + { + print $html->form_users($_SERVER['PHP_SELF'].'?rowid='.$adh->id,$adh->user_id,'none'); + } + else print $langs->trans("NoDolibarrAccess"); + } + print '
\n"; print ''; diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 989593987de..17dbaf66396 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -51,10 +51,7 @@ if (! empty($_REQUEST['socid_id'])) } // Security check -if (! $user->rights->adherent->lire) -{ - accessforbidden(); -} +if (! $user->rights->adherent->lire) accessforbidden(); $adh = new Adherent($db); $adho = new AdherentOptions($db); @@ -318,18 +315,8 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adhe } else { - if ($adh->error) - { - $errmsg=$adh->error; - } - else - { - foreach($adh->errors as $error) - { - if ($errmsg) $errmsg.='
'; - $errmsg.=$error; - } - } + if ($adh->error) $errmsg=$adh->error; + else $errmsgs=$adh->errors; $action=''; } } @@ -475,7 +462,7 @@ if ($_POST["action"] == 'add' && $user->rights->adherent->creer) $db->rollback(); if ($adh->error) $errmsg=$adh->error; - else $errmsg=$adh->errors[0]; + else $errmsgs=$adh->errors; $action = 'create'; } @@ -527,19 +514,8 @@ if ($user->rights->adherent->creer && $_POST["action"] == 'confirm_valid' && $_P } else { - // \TODO Mettre fonction qui fabrique errmsg depuis this->error||this->errors - if ($adh->error) - { - $errmsg=$adh->error; - } - else - { - foreach($adh->errors as $error) - { - if ($errmsg) $errmsg.='
'; - $errmsg.=$error; - } - } + if ($adh->error) $errmsg=$adh->error; + else $errmsgs=$adh->errors; $action=''; } } @@ -571,19 +547,8 @@ if ($user->rights->adherent->supprimer && $_POST["action"] == 'confirm_resign' & } else { - // \TODO Mettre fonction qui fabrique errmsg depuis this->error||this->errors - if ($adh->error) - { - $errmsg=$adh->error; - } - else - { - foreach($adh->errors as $error) - { - if ($errmsg) $errmsg.='
'; - $errmsg.=$error; - } - } + if ($adh->error) $errmsg=$adh->error; + else $errmsgs=$adh->errors; $action=''; } } @@ -857,10 +822,8 @@ if ($action == 'edit') dol_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user'); - if ($errmsg) - { - print '
'.$errmsg.'
'; - } + dol_htmloutput_errors($errmsg,$errmsgs); + if ($mesg) print '
'.$mesg.'
'; @@ -1195,7 +1158,6 @@ if ($rowid && $action != 'edit') $rowspan=15+sizeof($adho->attribute_label); if ($conf->societe->enabled) $rowspan++; - print ''; print ''; // Ref @@ -1289,9 +1251,9 @@ if ($rowid && $action != 'edit') print '
'; if ($_GET['action'] == 'editthirdparty') { - $page=$_SERVER['PHP_SELF'].'?rowid='.$adh->id; $htmlname='socid'; - print '
'; + print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index a0e5158dbd4..8b8a10f7d80 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1636,6 +1636,7 @@ class Facture extends CommonObject $total_ttc = $tabprice[2]; $total_localtax1 = $tabprice[9]; $total_localtax2 = $tabprice[10]; + $pu_ht = $tabprice[3]; // Rang to use $rangtouse = $rang; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index a49a21112fd..1b8f7cc43ed 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2113,7 +2113,7 @@ class Form if ($htmlname != "none") { - print ''; + print ''; print ''; print ''; print '
'; @@ -2151,7 +2151,7 @@ class Form global $langs; if ($htmlname != "none") { - print ''; + print ''; print ''; print ''; print '
';