diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index 024e21510e1..080fd46495c 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -6,7 +6,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2012-2014 Marcos GarcĂ­a - * Copyright (C) 2011-2014 Alexandre Spangaro + * Copyright (C) 2011-2015 Alexandre Spangaro * * 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 @@ -37,6 +37,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php' require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/donations/class/don.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; @@ -153,6 +154,7 @@ $paymentstatic=new Paiement($db); $paymentsupplierstatic=new PaiementFourn($db); $paymentvatstatic=new TVA($db); $paymentsalstatic=new PaymentSalary($db); +$donstatic=new Don($db); $bankstatic=new Account($db); $banklinestatic=new AccountLine($db); @@ -705,6 +707,21 @@ if ($id > 0 || ! empty($ref)) $chargestatic->ref=$chargestatic->lib; print $chargestatic->getNomUrl(1,16); } + else if ($links[$key]['type']=='donation') + { + $donstatic->id=$links[$key]['url_id']; + if (preg_match('/^\((.*)\)$/i',$links[$key]['label'],$reg)) + { + if ($reg[1]=='donation') $reg[1]='Donation'; + $donstatic->lib=$langs->trans($reg[1]); + } + else + { + $donstatic->lib=$links[$key]['label']; + } + $donstatic->ref=$donstatic->lib; + print $donstatic->getNomUrl(1,16); + } else if ($links[$key]['type']=='member') { $memberstatic->id=$links[$key]['url_id']; diff --git a/htdocs/donations/card.php b/htdocs/donations/card.php index 300e18f1ad0..a8424da558e 100644 --- a/htdocs/donations/card.php +++ b/htdocs/donations/card.php @@ -526,10 +526,10 @@ if (! empty($id) && $action != 'edit') print yn($object->public); print ''; - print "".''.$langs->trans("Company").''.$object->societe.''; - print "".''.$langs->trans("Lastname").''.$object->lastname.''; - print "".''.$langs->trans("Firstname").''.$object->firstname.''; - print "".''.$langs->trans("Address").''.dol_nl2br($object->address).''; + print ''.$langs->trans("Company").''.$object->societe.''; + print ''.$langs->trans("Lastname").''.$object->lastname.''; + print ''.$langs->trans("Firstname").''.$object->firstname.''; + print ''.$langs->trans("Address").''.dol_nl2br($object->address).''; $rowspan=6; if (! empty($conf->projet->enabled)) $rowspan++; @@ -543,7 +543,7 @@ if (! empty($id) && $action != 'edit') $sql.= " FROM ".MAIN_DB_PREFIX."payment_donation as p"; $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; $sql.= ", ".MAIN_DB_PREFIX."don as d"; - $sql.= " WHERE d.rowid = '".$rowid."'"; + $sql.= " WHERE d.rowid = '".$id."'"; $sql.= " AND p.fk_donation = d.rowid"; $sql.= " AND d.entity = ".$conf->entity; $sql.= " AND p.fk_typepayment = c.id"; @@ -570,25 +570,25 @@ if (! empty($id) && $action != 'edit') $objp = $db->fetch_object($resql); $var=!$var; print ""; - print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''; + print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''; print ''.dol_print_date($db->jdate($objp->dp),'day')."\n"; $labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->paiement_type; print "".$labeltype.' '.$object->num_paiement."\n"; - print ''.price($object->amount)." ".$langs->trans("Currency".$conf->currency)."\n"; + print ''.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."\n"; print ""; - $totalpaid += $object->amount; + $totalpaid += $objp->amount; $i++; } if ($object->paid == 0) { - print "".$langs->trans("AlreadyPaid")." :".price($totalpaye)." ".$langs->trans("Currency".$conf->currency)."\n"; + print "".$langs->trans("AlreadyPaid")." :".price($totalpaid)." ".$langs->trans("Currency".$conf->currency)."\n"; print "".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."\n"; $remaintopay = $object->amount - $totalpaid; print "".$langs->trans("RemainderToPay")." :"; - print "".price($resteapayer)." ".$langs->trans("Currency".$conf->currency)."\n"; + print "".price($remaintopay)." ".$langs->trans("Currency".$conf->currency)."\n"; } print ""; $db->free($resql); @@ -679,7 +679,7 @@ if (! empty($id) && $action != 'edit') } else { - print ''; + print ''; } } diff --git a/htdocs/donations/class/don.class.php b/htdocs/donations/class/don.class.php index 478f4cce7c0..e02ecefccbc 100644 --- a/htdocs/donations/class/don.class.php +++ b/htdocs/donations/class/don.class.php @@ -370,7 +370,7 @@ class Don extends CommonObject if ($result) { // Actions on extra fields (by external module) - $hookmanager->initHooks(array('dondao')); + /*$hookmanager->initHooks(array('dondao')); $parameters=array('id'=>$this->id); $action=''; $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks @@ -386,6 +386,7 @@ class Don extends CommonObject } } else if ($reshook < 0) $error++; + */ $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."don"); diff --git a/htdocs/donations/class/paymentdonation.class.php b/htdocs/donations/class/paymentdonation.class.php index 72d1709b252..9125ea68d57 100644 --- a/htdocs/donations/class/paymentdonation.class.php +++ b/htdocs/donations/class/paymentdonation.class.php @@ -317,7 +317,7 @@ class PaymentDonation extends CommonObject if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; - $sql.= " WHERE type='payment_sc' AND url_id=".$this->id; + $sql.= " WHERE type='payment_donation' AND url_id=".$this->id; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql = $this->db->query($sql); @@ -382,7 +382,7 @@ class PaymentDonation extends CommonObject $error=0; - $object=new PaymentSocialContribution($this->db); + $object=new PaymentDonation($this->db); $object->context['createfromclone'] = 'createfromclone'; @@ -461,7 +461,7 @@ class PaymentDonation extends CommonObject * All payment properties must have been set first like after a call to create(). * * @param User $user Object of user making payment - * @param string $mode 'payment_sc' + * @param string $mode 'payment_donation' * @param string $label Label to use in bank record * @param int $accountid Id of bank account to do link with * @param string $emetteur_nom Name of transmitter @@ -482,7 +482,7 @@ class PaymentDonation extends CommonObject $acc->fetch($accountid); $total=$this->total; - if ($mode == 'payment_sc') $total=-$total; + if ($mode == 'payment_donation') $total=-$total; // Insert payment into llx_bank $bank_line_id = $acc->addline( @@ -508,9 +508,9 @@ class PaymentDonation extends CommonObject dol_print_error($this->db); } - // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction + // Add link 'payment', 'payment_supplier', 'payment_donation' in bank_url between payment and bank transaction $url=''; - if ($mode == 'payment_donation') $url=DOL_URL_ROOT.'/donations/card.php?rowid='; + if ($mode == 'payment_donation') $url=DOL_URL_ROOT.'/donations/payment/card.php?rowid='; if ($url) { $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); @@ -529,7 +529,7 @@ class PaymentDonation extends CommonObject { $don = new Don($this->db); $don->fetch($key); - $result=$acc->add_url_line($bank_line_id, $don->rowid, DOL_URL_ROOT.'/compta/card.php?rowid=', $don->type_libelle.(($don->lib && $don->lib!=$don->type_libelle)?' ('.$don->lib.')':''),'sc'); + $result=$acc->add_url_line($bank_line_id, $don->rowid, DOL_URL_ROOT.'/donations/card.php?rowid=', $don->type_libelle.(($don->lib && $don->lib!=$don->type_libelle)?' ('.$don->lib.')':''),'donation'); if ($result <= 0) dol_print_error($this->db); } } @@ -593,7 +593,7 @@ class PaymentDonation extends CommonObject if (!empty($this->id)) { - $link = ''; + $link = ''; $linkend=''; if ($withpicto) $result.=($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); @@ -603,6 +603,4 @@ class PaymentDonation extends CommonObject return $result; } -} - - +} \ No newline at end of file diff --git a/htdocs/donations/payment/card.php b/htdocs/donations/payment/card.php new file mode 100644 index 00000000000..3e4d03d15d2 --- /dev/null +++ b/htdocs/donations/payment/card.php @@ -0,0 +1,312 @@ + + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/donations/payment/card.php + * \ingroup donations + * \brief Tab payment of a donation + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/donations/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/donations/class/paymentdonation.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; +if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + +$langs->load('bills'); +$langs->load('banks'); +$langs->load('companies'); + +// Security check +$id=GETPOST("id"); +$action=GETPOST("action"); +$confirm=GETPOST('confirm'); +if ($user->societe_id) $socid=$user->societe_id; +// TODO Add rule to restrict access payment +//$result = restrictedArea($user, 'facture', $id,''); + +$payment = new PaymentDonation($db); +if ($id > 0) +{ + $result=$payment->fetch($id); + if (! $result) dol_print_error($db,'Failed to get payment id '.$id); +} + + +/* + * Actions + */ + +// Delete payment +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->don->supprimer) +{ + $db->begin(); + + $result = $payment->delete($user); + if ($result > 0) + { + $db->commit(); + header("Location: ".DOL_URL_ROOT."/donations/index.php"); + exit; + } + else + { + setEventMessage($payment->error, 'errors'); + $db->rollback(); + } +} + +// Create payment +if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->don->creer) +{ + $db->begin(); + + $result=$payment->valide(); + + if ($result > 0) + { + $db->commit(); + + $factures=array(); // TODO Get all id of invoices linked to this payment + foreach($factures as $id) + { + $fac = new Facture($db); + $fac->fetch($id); + + $outputlangs = $langs; + if (! empty($_REQUEST['lang_id'])) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $fac->generateDocument($fac->modelpdf, $outputlangs); + } + } + + header('Location: card.php?id='.$payment->id); + exit; + } + else + { + setEventMessage($payment->error); + $db->rollback(); + } +} + + +/* + * View + */ + +llxHeader(); + +$don = new Don($db); +$form = new Form($db); + +$h=0; + +$head[$h][0] = DOL_URL_ROOT.'/donations/payment/card.php?id='.$_GET["id"]; +$head[$h][1] = $langs->trans("Card"); +$hselected = $h; +$h++; + +dol_fiche_head($head, $hselected, $langs->trans("PaymentDonation"), 0, 'payment'); + +/* + * Confirmation de la suppression du paiement + */ +if ($action == 'delete') +{ + print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); + +} + +/* + * Confirmation de la validation du paiement + */ +if ($action == 'valide') +{ + $facid = $_GET['facid']; + print $form->formconfirm('card.php?id='.$payment->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); + +} + + +print ''; + +// Ref +print ''; +print ''; + +// Date +print ''; + +// Mode +print ''; + +// Number +print ''; + +// Amount +print ''; + +// Note +print ''; + +// Bank account +if (! empty($conf->banque->enabled)) +{ + if ($payment->bank_account) + { + $bankline=new AccountLine($db); + $bankline->fetch($payment->bank_line); + + print ''; + print ''; + print ''; + print ''; + } +} + +print '
'.$langs->trans('Ref').''; +print $form->showrefnav($payment,'id','',1,'rowid','id'); +print '
'.$langs->trans('Date').''.dol_print_date($payment->datep,'day').'
'.$langs->trans('Mode').''.$langs->trans("PaymentType".$payment->type_code).'
'.$langs->trans('Number').''.$payment->num_paiement.'
'.$langs->trans('Amount').''.price($payment->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Note').''.nl2br($payment->note).'
'.$langs->trans('BankTransactionLine').''; + print $bankline->getNomUrl(1,0,'showall'); + print '
'; + + +/* + * List of donations payed + */ + +$disable_delete = 0; +$sql = 'SELECT d.rowid as did, d.libelle, d.paid, d.amount as d_amount, pd.amount, pd.libelle as d_type'; +$sql.= ' FROM '.MAIN_DB_PREFIX.'payment_donation as pd,'.MAIN_DB_PREFIX.'don as d'; +$sql.= ' WHERE pd.fk_donation = d.rowid'; +$sql.= ' AND d.entity = '.$conf->entity; +$sql.= ' AND pd.rowid = '.$id; + +dol_syslog("donations/payment/card.php", LOG_DEBUG); +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + + $i = 0; + $total = 0; + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + if ($num > 0) + { + $var=True; + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + $var=!$var; + print ''; + // Ref + print '\n"; + // Type + print '\n"; + // Label + print ''; + // Expected to pay + print ''; + // Status + print ''; + // Amount payed + print ''; + print "\n"; + if ($objp->paid == 1) // If at least one invoice is paid, disable delete + { + $disable_delete = 1; + } + $total = $total + $objp->amount; + $i++; + } + } + $var=!$var; + + print "
'.$langs->trans('Donation').''.$langs->trans('Type').''.$langs->trans('Label').''.$langs->trans('ExpectedToPay').''.$langs->trans('Status').''.$langs->trans('PayedByThisPayment').'
'; + $don->fetch($objp->did); + print $don->getNomUrl(1); + print "'; + print $don->type_libelle; + /*print $don->type;*/ + print "'.$objp->libelle.''.price($objp->d_amount).''.$don->getLibStatut(4,$objp->amount).''.price($objp->amount).'
\n"; + $db->free($resql); +} +else +{ + dol_print_error($db); +} + +print ''; + + +/* + * Boutons Actions + */ +print '
'; + +/* +if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) +{ + if ($user->societe_id == 0 && $payment->statut == 0 && $_GET['action'] == '') + { + if ($user->rights->facture->paiement) + { + print ''.$langs->trans('Valid').''; + } + } +} +*/ + +if ($_GET['action'] == '') +{ + if ($user->rights->don->supprimer) + { + if (! $disable_delete) + { + print ''.$langs->trans('Delete').''; + } + else + { + print ''.$langs->trans('Delete').''; + } + } +} + +print '
'; + + + +llxFooter(); + +$db->close(); diff --git a/htdocs/donations/payment/index.html b/htdocs/donations/payment/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/donations/payment.php b/htdocs/donations/payment/payment.php similarity index 99% rename from htdocs/donations/payment.php rename to htdocs/donations/payment/payment.php index b86678dcd39..871bbaa1056 100644 --- a/htdocs/donations/payment.php +++ b/htdocs/donations/payment/payment.php @@ -21,7 +21,7 @@ * \brief Page to add payment of a donation */ -require '../main.inc.php'; +require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/donations/class/don.class.php'; require_once DOL_DOCUMENT_ROOT.'/donations/class/paymentdonation.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';