FIX Payment mode not correctly set in donation and document

This commit is contained in:
Laurent Destailleur 2018-03-02 12:32:49 +01:00
parent a01287b211
commit 8d11f1efa1
4 changed files with 63 additions and 53 deletions

View File

@ -3,7 +3,7 @@
* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2014-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2014-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Benoit Bruchard <benoitb21@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
@ -89,7 +89,7 @@ class html_cerfafr extends ModeleDon
$outputlangs->load("donations");
$currency = !empty($currency) ? $currency : $conf->currency;
if (! empty($conf->don->dir_output))
{
// Definition of the object don (for upward compatibility)
@ -134,21 +134,21 @@ class html_cerfafr extends ModeleDon
$paymentmode = $formclass->cache_types_paiements[$don->modepaiementid]['label'];
}
else $paymentmode = '';
if ($don->modepaiementid==7){
if ($don->modepaymentcode=='CHQ'){
$ModePaiement = '<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox" disabled="true" checked="checked"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>';
}
else if ($don->modepaiementid==4){
else if ($don->modepaymentcode=='LIQ'){
$ModePaiement = '<td width="25%"><input type="checkbox" checked="checked"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>';
}
else if ($don->modepaiementid==2 || $don->modepaiementid==3 || $don->modepaiementid==6){
else if ($don->modepaymentcode=='VIR' || $don->modepaymentcode=='PRE' || $don->modepaymentcode=='CB'){
$ModePaiement = '<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox" checked="checked"> Virement, prélèvement, carte bancaire</td>';
}
else
}
else
{
$ModePaiement = '<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>';
}
/*
if (empty($don->societe))
{
@ -159,14 +159,14 @@ class html_cerfafr extends ModeleDon
$CodeDon = '<td width="33%"><input type="checkbox" disabled="true" > 200 du CGI</td><td width="33%"><input type="checkbox" disabled="true" checked="checked" > 238 bis du CGI</td><td width="33%"><input type="checkbox" disabled="true" > 885-0 V bis A du CGI</td>';
}
*/
// Define contents
$donmodel=DOL_DOCUMENT_ROOT ."/core/modules/dons/html_cerfafr.html";
$form = implode('', file($donmodel));
$form = str_replace('__REF__',$don->id,$form);
$form = str_replace('__DATE__',dol_print_date($don->date,'day',false,$outputlangs),$form);
//$form = str_replace('__IP__',$user->ip,$form); // TODO $user->ip not exist
$form = str_replace('__AMOUNT__',$don->amount,$form);
$form = str_replace('__AMOUNT__', price($don->amount), $form);
$form = str_replace('__AMOUNTLETTERS__',chiffre_en_lettre($don->amount),$form);
$form = str_replace('__CURRENCY__',$outputlangs->transnoentitiesnoconv("Currency".$currency),$form);
$form = str_replace('__CURRENCYCODE__',$conf->currency,$form);
@ -183,7 +183,6 @@ class html_cerfafr extends ModeleDon
$form = str_replace('__DONATOR_ZIP__',$don->zip,$form);
$form = str_replace('__DONATOR_TOWN__',$don->town,$form);
$form = str_replace('__PAYMENTMODE_LIB__ ', $paymentmode,$form);
$form = str_replace('__ModePaiement__', $ModePaiement,$form);
$form = str_replace('__NOW__',dol_print_date($now,'day',false,$outputlangs),$form);
$form = str_replace('__DonationRef__',$outputlangs->trans("DonationRef"),$form);
$form = str_replace('__DonationTitle__',$outputlangs->trans("DonationTitle"),$form);
@ -204,6 +203,8 @@ class html_cerfafr extends ModeleDon
$form = str_replace('__IConfirmDonationReception__',$outputlangs->trans("IConfirmDonationReception"),$form);
$form = str_replace('__DonationMessage__',$conf->global->DONATION_MESSAGE,$form);
$form = str_replace('__ModePaiement__', $ModePaiement,$form);
$frencharticle='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) $frencharticle='<font size="+1">Article 200, 238 bis et 885-0 V bis A du code général des impôts (CGI)</font>';
$form = str_replace('__FrenchArticle__',$frencharticle,$form);
@ -260,7 +261,7 @@ class html_cerfafr extends ModeleDon
@chmod($file, octdec($conf->global->MAIN_UMASK));
$this->result = array('fullpath'=>$file);
return 1;
}
else
@ -394,34 +395,34 @@ function chiffre_en_lettre($montant, $devise1='', $devise2='')
if($cent[$i]==1) $trio[$i]='cent';
else if($cent[$i]!=0 || $cent[$i]!='') $trio[$i]=$chif[$cent[$i]] .' cents';
}
$chif2=array('', 'dix', 'vingt', 'trente', 'quarante', 'cinquante', 'soixante', 'soixante-dix', 'quatre-vingts', 'quatre-vingts dix');
$secon_c=$chif2[$dix_c];
if($cent_c==1) $trio_c='cent';
else if($cent_c!=0 || $cent_c!='') $trio_c=$chif[$cent_c] .' cents';
if(($cent[3]==0 || $cent[3]=='') && ($dix[3]==0 || $dix[3]=='') && ($unite[3]==1))
$somme = $trio[3]. ' ' .$secon[3]. ' ' . $prim[3]. ' million ';
else if(($cent[3]!=0 && $cent[3]!='') || ($dix[3]!=0 && $dix[3]!='') || ($unite[3]!=0 && $unite[3]!=''))
$somme = $trio[3]. ' ' .$secon[3]. ' ' . $prim[3]. ' millions ';
else
$somme = $trio[3]. ' ' .$secon[3]. ' ' . $prim[3];
if(($cent[2]==0 || $cent[2]=='') && ($dix[2]==0 || $dix[2]=='') && ($unite[2]==1))
$somme = $somme.' mille ';
else if(($cent[2]!=0 && $cent[2]!='') || ($dix[2]!=0 && $dix[2]!='') || ($unite[2]!=0 && $unite[2]!=''))
$somme = $somme. $trio[2]. ' ' .$secon[2]. ' ' . $prim[2]. ' milles ';
else
$somme = $somme. $trio[2]. ' ' .$secon[2]. ' ' . $prim[2];
$somme = $somme. $trio[1]. ' ' .$secon[1]. ' ' . $prim[1];
$somme = $somme. ' '. $dev1 .' ' ;
if(($cent_c=='0' || $cent_c=='') && ($dix_c=='0' || $dix_c==''))
return $somme. ' et z&eacute;ro '. $dev2;
else
return $somme. $trio_c. ' ' .$secon_c. ' ' . $dev2;
}

View File

@ -98,20 +98,21 @@ if ($action == 'update')
{
$object->fetch($id);
$object->firstname = GETPOST("firstname");
$object->lastname = GETPOST("lastname");
$object->societe = GETPOST("societe");
$object->address = GETPOST("address");
$object->amount = price2num(GETPOST("amount"));
$object->town = GETPOST("town");
$object->zip = GETPOST("zipcode");
$object->firstname = GETPOST("firstname",'alpha');
$object->lastname = GETPOST("lastname",'alpha');
$object->societe = GETPOST("societe",'alpha');
$object->address = GETPOST("address",'alpha');
$object->amount = price2num(GETPOST("amount",'alpha'));
$object->town = GETPOST("town",'alpha');
$object->zip = GETPOST("zipcode",'alpha');
$object->country_id = GETPOST('country_id', 'int');
$object->email = GETPOST("email");
$object->email = GETPOST("email",'alpha');
$object->date = $donation_date;
$object->public = GETPOST("public");
$object->fk_project = GETPOST("fk_project");
$object->note_private= GETPOST("note_private");
$object->note_public = GETPOST("note_public");
$object->public = GETPOST("public",'alpha');
$object->fk_project = GETPOST("fk_project",'alpha');
$object->note_private= GETPOST("note_private",'none');
$object->note_public = GETPOST("note_public",'none');
$object->modepaymentid = GETPOST('modepayment','int');
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
@ -151,20 +152,21 @@ if ($action == 'add')
if (! $error)
{
$object->firstname = GETPOST("firstname");
$object->lastname = GETPOST("lastname");
$object->societe = GETPOST("societe");
$object->address = GETPOST("address");
$object->amount = price2num(GETPOST("amount"));
$object->zip = GETPOST("zipcode");
$object->town = GETPOST("town");
$object->firstname = GETPOST("firstname",'alpha');
$object->lastname = GETPOST("lastname",'alpha');
$object->societe = GETPOST("societe",'alpha');
$object->address = GETPOST("address",'alpha');
$object->amount = price2num(GETPOST("amount",'alpha'));
$object->zip = GETPOST("zipcode",'alpha');
$object->town = GETPOST("town",'alpha');
$object->country_id = GETPOST('country_id', 'int');
$object->email = GETPOST("email");
$object->email = GETPOST("email",'alpha');
$object->date = $donation_date;
$object->note_private= GETPOST("note_private");
$object->note_public = GETPOST("note_public");
$object->public = GETPOST("public");
$object->fk_project = GETPOST("fk_project");
$object->note_private= GETPOST("note_private",'none');
$object->note_public = GETPOST("note_public",'none');
$object->public = GETPOST("public",'alpha');
$object->fk_project = GETPOST("fk_project",'alpha');
$object->modepaymentid = GETPOST('modepayment','int');
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
@ -348,6 +350,12 @@ if ($action == 'create')
print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" value="'.dol_escape_htmltag(GETPOST("email")).'" class="maxwidth200"></td></tr>';
// Payment mode
print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n";
$selected = GETPOST('modepayment','int');
$form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1);
print "</td></tr>\n";
// Public note
print '<tr>';
print '<td class="tdtop">' . $langs->trans('NotePublic') . '</td>';
@ -480,14 +488,14 @@ if (! empty($id) && $action == 'edit')
print "<tr>".'<td>'.$langs->trans("EMail").'</td><td><input type="text" name="email" class="maxwidth200" value="'.dol_escape_htmltag($object->email).'"></td></tr>';
// Payment mode
print "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n";
if ($object->modepaymentid) $selected = $object->modepaymentid;
else $selected = '';
$form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1);
print "</td></tr>\n";
// Status
print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
// Project

View File

@ -69,7 +69,7 @@ class Don extends CommonObject
global $langs;
$this->db = $db;
$this->modepaiementid = 0;
$this->modepaymentid = 0;
$langs->load("donations");
$this->labelstatut[-1]=$langs->trans("Canceled");
@ -338,7 +338,6 @@ class Don extends CommonObject
$sql.= ", address";
$sql.= ", zip";
$sql.= ", town";
// $sql.= ", country"; -- Deprecated
$sql.= ", fk_country";
$sql.= ", public";
$sql.= ", fk_projet";
@ -354,7 +353,7 @@ class Don extends CommonObject
$sql.= " '".$this->db->idate($now)."'";
$sql.= ", ".$conf->entity;
$sql.= ", ".price2num($this->amount);
$sql.= ", ".($this->modepaiementid?$this->modepaiementid:"null");
$sql.= ", ".($this->modepaymentid?$this->modepaymentid:"null");
$sql.= ", '".$this->db->escape($this->firstname)."'";
$sql.= ", '".$this->db->escape($this->lastname)."'";
$sql.= ", '".$this->db->escape($this->societe)."'";
@ -605,9 +604,10 @@ class Don extends CommonObject
$sql = "SELECT d.rowid, d.datec, d.date_valid, d.tms as datem, d.datedon,";
$sql.= " d.firstname, d.lastname, d.societe, d.amount, d.fk_statut, d.address, d.zip, d.town, ";
$sql.= " d.fk_country, d.country as country_olddata, d.public, d.amount, d.fk_payment, d.paid, d.note_private, d.note_public, cp.libelle, d.email, d.phone, ";
$sql.= " d.fk_country, d.country as country_olddata, d.public, d.amount, d.fk_payment, d.paid, d.note_private, d.note_public, d.email, d.phone, ";
$sql.= " d.phone_mobile, d.fk_projet as fk_project, d.model_pdf,";
$sql.= " p.ref as project_ref,";
$sql.= " cp.libelle as payment_label, cp.code as payment_code,";
$sql.= " c.code as country_code, c.label as country";
$sql.= " FROM ".MAIN_DB_PREFIX."don as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_projet";
@ -657,7 +657,8 @@ class Don extends CommonObject
$this->fk_project = $obj->fk_project;
$this->public = $obj->public;
$this->modepaymentid = $obj->fk_payment;
$this->modepayment = $obj->libelle;
$this->modepaymentcode = $obj->payment_code;
$this->modepayment = $obj->payment_label;
$this->paid = $obj->paid;
$this->amount = $obj->amount;
$this->note_private = $obj->note_private;

View File

@ -29,7 +29,7 @@ create table llx_don
fk_statut smallint NOT NULL DEFAULT 0, -- Status of donation promise or validate
datedon datetime, -- Date of the donation/promise
amount double(24,8) DEFAULT 0,
fk_payment integer,
fk_payment integer, -- Id of payment mode
paid smallint default 0 NOT NULL,
firstname varchar(50),
lastname varchar(50),