diff --git a/htdocs/adherents/card_subscriptions.php b/htdocs/adherents/card_subscriptions.php index d1787ad7ae7..491cbcf8b79 100644 --- a/htdocs/adherents/card_subscriptions.php +++ b/htdocs/adherents/card_subscriptions.php @@ -165,93 +165,93 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio $langs->load("banks"); - $result=$adh->fetch($rowid); - $result=$adht->fetch($adh->typeid); + $result=$adh->fetch($rowid); + $result=$adht->fetch($adh->typeid); - // Subscription informations - $datecotisation=0; - $datesubend=0; - if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"]) - { - $datecotisation=dol_mktime(0, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - } - if ($_POST["endyear"] && $_POST["endmonth"] && $_POST["endday"]) - { - $datesubend=dol_mktime(0, 0, 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); - } - $cotisation=$_POST["cotisation"]; // Amount of subscription - $label=$_POST["label"]; + // Subscription informations + $datecotisation=0; + $datesubend=0; + if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"]) + { + $datecotisation=dol_mktime(0, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + } + if ($_POST["endyear"] && $_POST["endmonth"] && $_POST["endday"]) + { + $datesubend=dol_mktime(0, 0, 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); + } + $cotisation=$_POST["cotisation"]; // Amount of subscription + $label=$_POST["label"]; - if (! $datecotisation) - { - $error++; - $errmsg=$langs->trans("BadDateFormat"); - $action='addsubscription'; - } - if (! $datesubend) - { - $datesubend=dol_time_plus_duree(dol_time_plus_duree($datecotisation,$defaultdelay,$defaultdelayunit),-1,'d'); - } + if (! $datecotisation) + { + $error++; + $errmsg=$langs->trans("BadDateFormat"); + $action='addsubscription'; + } + if (! $datesubend) + { + $datesubend=dol_time_plus_duree(dol_time_plus_duree($datecotisation,$defaultdelay,$defaultdelayunit),-1,'d'); + } - // Payment informations - $accountid=$_POST["accountid"]; - $operation=$_POST["operation"]; // Payment mode - $num_chq=$_POST["num_chq"]; - $emetteur_nom=$_POST["chqemetteur"]; - $emetteur_banque=$_POST["chqbank"]; + // Payment informations + $accountid=$_POST["accountid"]; + $operation=$_POST["operation"]; // Payment mode + $num_chq=$_POST["num_chq"]; + $emetteur_nom=$_POST["chqemetteur"]; + $emetteur_banque=$_POST["chqbank"]; $option=$_POST["paymentsave"]; if (empty($option)) $option='none'; - // Check if a payment is mandatory or not - if (! $error && $adht->cotisation) // Type adherent soumis a cotisation - { - if (! is_numeric($_POST["cotisation"])) - { - // If field is '' or not a numeric value - $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")); + // Check if a payment is mandatory or not + if (! $error && $adht->cotisation) // Type adherent soumis a cotisation + { + if (! is_numeric($_POST["cotisation"])) + { + // If field is '' or not a numeric value + $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")); $error++; - $action='addsubscription'; - } - else - { - if ($conf->banque->enabled && $_POST["paymentsave"] != 'none') - { - if ($_POST["cotisation"]) - { - if (! $_POST["label"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")); - if (! $_POST["operation"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")); - if (! $_POST["accountid"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("FinancialAccount")); - } - else - { - if ($_POST["accountid"]) $errmsg=$langs->trans("ErrorDoNotProvideAccountsIfNullAmount"); - } - if ($errmsg) $action='addsubscription'; - } - } - } + $action='addsubscription'; + } + else + { + if ($conf->banque->enabled && $_POST["paymentsave"] != 'none') + { + if ($_POST["cotisation"]) + { + if (! $_POST["label"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")); + if (! $_POST["operation"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")); + if (! $_POST["accountid"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("FinancialAccount")); + } + else + { + if ($_POST["accountid"]) $errmsg=$langs->trans("ErrorDoNotProvideAccountsIfNullAmount"); + } + if ($errmsg) $action='addsubscription'; + } + } + } - if (! $error && $action=='cotisation') - { - $db->begin(); + if (! $error && $action=='cotisation') + { + $db->begin(); - $crowid=$adh->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $option); + $crowid=$adh->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $option); - if ($crowid <= 0) - { - $error++; - $errmsg=$adh->error; - } + if ($crowid <= 0) + { + $error++; + $errmsg=$adh->error; + } - if (! $error) - { - if ($option == 'bankviainvoice' || $option == 'invoiceonly') - { + if (! $error) + { + if ($option == 'bankviainvoice' || $option == 'invoiceonly') + { // If option choosed, we create invoice require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/paymentterm.class.php"); - $invoice=new Facture($db); + $invoice=new Facture($db); $customer=new Societe($db); $result=$customer->fetch($adh->fk_soc); if ($result <= 0) @@ -265,13 +265,13 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio $invoice->cond_reglement_id=$customer->cond_reglement_id; if (empty($invoice->cond_reglement_id)) { - $paymenttermstatic=new PaymentTerm($db); - $invoice->cond_reglement_id=$paymenttermstatic->getDefaultId(); - if (empty($invoice->cond_reglement_id)) - { - $error++; - $errmsg='ErrorNoPaymentTermRECEPFound'; - } + $paymenttermstatic=new PaymentTerm($db); + $invoice->cond_reglement_id=$paymenttermstatic->getDefaultId(); + if (empty($invoice->cond_reglement_id)) + { + $error++; + $errmsg='ErrorNoPaymentTermRECEPFound'; + } } $invoice->socid=$adh->fk_soc; $invoice->date=$datecotisation; @@ -294,32 +294,60 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio $error++; } + // Validate invoice $result=$invoice->validate($user); - if ($option == 'bankviainvoice') - { + if ($option == 'bankviainvoice') + { // Now we add payment - // TODO + require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'); + require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); + // Creation de la ligne paiement + $amounts[$invoice->id] = price2num($cotisation); + $paiement = new Paiement($db); + $paiement->datepaye = $datecotisation; + $paiement->amounts = $amounts; + $paiement->paiementid = $operation; + $paiement->num_paiement = $num_chq; + $paiement->note = $label; - } - } - } + if (! $error) + { + $paiement_id = $paiement->create($user); + if (! $paiement_id > 0) + { + $errmsg=$paiement->error; + $error++; + } + } - if (! $error) - { - $db->commit(); - } - else - { - $db->rollback(); - $errmsg=$adh->error; - $action = 'addsubscription'; - } + if (! $error) + { + $result=$paiement->addLinkInvoiceBank($user,'(SubscriptionPayment)',$accountid,$emetteur_nom,$emetteur_banque); + if (! $result > 0) + { + $errmsg=$paiement->error; + $error++; + } + } + } + } + } - // Send email - if (! $error) - { + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + $action = 'addsubscription'; + } + + // Send email + if (! $error) + { // Send confirmation Email if ($adh->email && $_POST["sendmail"]) { @@ -335,8 +363,8 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio $_POST["operation"]=''; $_POST["label"]=''; $_POST["num_chq"]=''; - } - } + } + } } @@ -464,10 +492,10 @@ if ($rowid) 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); - }*/ + 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 @@ -488,12 +516,12 @@ if ($rowid) if ($errmsg) { - if (preg_match('/^Error/i',$errmsg)) - { - $langs->load("errors"); - $errmsg=$langs->trans($errmsg); - } - print '
| '.$langs->trans("Ref").' | '; - print ''.$langs->trans("DateSubscription").' | '; - print ''.$langs->trans("DateEnd").' | '; - print ''.$langs->trans("Amount").' | '; - if ($conf->banque->enabled) - { - print ''.$langs->trans("Account").' | '; - } - print "
| '.$langs->trans("Ref").' | '; + print ''.$langs->trans("DateSubscription").' | '; + print ''.$langs->trans("DateEnd").' | '; + print ''.$langs->trans("Amount").' | '; + if ($conf->banque->enabled) + { + print ''.$langs->trans("Account").' | '; + } + print "
| '.$cotisationstatic->getNomUrl(1).' | '; - print ''.dol_print_date($db->jdate($objp->dateadh),'day')." | \n"; - print ''.dol_print_date($db->jdate($objp->datef),'day')." | \n"; - print ''.price($objp->cotisation).' | '; - if ($conf->banque->enabled) - { - print ''; - if ($objp->bid) - { - $accountstatic->label=$objp->label; - $accountstatic->id=$objp->baid; - print $accountstatic->getNomUrl(1); - } - else - { - print ' '; - } - print ' | '; - } - print "