* Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2013 Florian Henry * Copyright (C) 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 * 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/don/card.php * \ingroup donations * \brief Page of donation card */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; if (! empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; } require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $langs->load("companies"); $langs->load("donations"); $langs->load("bills"); $id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int'); $action=GETPOST('action','alpha'); $cancel=GETPOST('cancel'); $amount=GETPOST('amount'); $donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $object = new Don($db); $extrafields = new ExtraFields($db); // Security check $result = restrictedArea($user, 'don', $id); // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('doncard','globalcard')); /* * Actions */ $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($action == 'update') { if (! empty($cancel)) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } $error=0; if (empty($donation_date)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors'); $action = "create"; $error++; } if (empty($amount)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors'); $action = "create"; $error++; } if (! $error) { $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->country_id = GETPOST('country_id', 'int'); $object->email = GETPOST("email"); $object->date = $donation_date; $object->public = GETPOST("public"); $object->fk_projet = GETPOST("fk_projet"); $object->note_private= GETPOST("note_private"); $object->note_public = GETPOST("note_public"); // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); if ($ret < 0) $error++; if ($object->update($user) > 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } } } if ($action == 'add') { if (! empty($cancel)) { header("Location: index.php"); exit; } $error=0; if (empty($donation_date)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors'); $action = "create"; $error++; } if (empty($amount)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors'); $action = "create"; $error++; } 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->country_id = GETPOST('country_id', 'int'); $object->email = GETPOST("email"); $object->date = $donation_date; $object->note_private= GETPOST("note_private"); $object->note_public = GETPOST("note_public"); $object->public = GETPOST("public"); $object->fk_projet = GETPOST("fk_projet"); // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); if ($ret < 0) $error++; if ($object->create($user) > 0) { header("Location: index.php"); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } } if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->don->supprimer) { $object->fetch($id); $result=$object->delete($user); if ($result > 0) { header("Location: index.php"); exit; } else { dol_syslog($object->error,LOG_DEBUG); setEventMessage($object->error,'errors'); setEventMessage($object->errors,'errors'); } } if ($action == 'valid_promesse') { if ($object->valid_promesse($id, $user->id) >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else { setEventMessage($object->error, 'errors'); } } if ($action == 'set_cancel') { if ($object->set_cancel($id) >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else { setEventMessage($object->error, 'errors'); } } if ($action == 'set_paid') { if ($object->set_paid($id, $modepayment) >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else { setEventMessage($object->error, 'errors'); } } // Remove file in doc form if ($action == 'remove_file') { $object = new Don($db, 0, $_GET['id']); if ($object->fetch($id)) { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $object->fetch_thirdparty(); $langs->load("other"); $upload_dir = $conf->don->dir_output; $file = $upload_dir . '/' . GETPOST('file'); $ret=dol_delete_file($file,0,0,0,$object); if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); $action=''; } } /* * Build doc */ if ($action == 'builddoc') { $object = new Don($db); $result=$object->fetch($id); // Save last template used to generate document if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $result=don_create($db, $object->id, '', $object->modelpdf, $outputlangs); if ($result <= 0) { dol_print_error($db,$result); exit; } } /* * View */ llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:Módulo_Donaciones'); $form=new Form($db); $formfile = new FormFile($db); $formcompany = new FormCompany($db); if ($action == 'create') { print_fiche_titre($langs->trans("AddDonation")); print '
'; print ''; print ''; dol_fiche_head(''); print ''; print ''; $nbrows=11; if (! empty($conf->projet->enabled)) $nbrows++; // Date print ''; // Amount print "".''; print '\n"; print "".''; print "".''; print "".''; print "".''; // Zip / Town print ''; // Country print ''; print "".''; // Public note print ''; print ''; print ''; // Private note if (empty($user->societe_id)) { print ''; print ''; print ''; } if (! empty($conf->projet->enabled)) { $formproject=new FormProjets($db); print "\n"; } // Other attributes $parameters=array('colspan' => 3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit',$parameters); } print ''; print "
'.$langs->trans("Date").''; $form->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1); print '
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("PublicDonation").""; print $form->selectyesno("public",isset($_POST["public"])?$_POST["public"]:1,1); print "
'.$langs->trans("Company").'
'.$langs->trans("Lastname").'
'.$langs->trans("Firstname").'
'.$langs->trans("Address").''; print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6); print ' '; print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id')); print '
'; print $form->select_country(GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); print '
'.$langs->trans("EMail").'
' . $langs->trans('NotePublic') . ''; $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); print $doleditor->Create(1); print '
' . $langs->trans('NotePrivate') . ''; $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); print $doleditor->Create(1); print '
".$langs->trans("Project").""; $formproject->select_projects(-1, GETPOST("fk_projet"),'fk_projet', 0, 0, 1, 1); print "
\n"; dol_fiche_end(); print '
     
'; print "
\n"; } /* ************************************************************ */ /* */ /* Donation card in edit mode */ /* */ /* ************************************************************ */ if (! empty($id) && $action == 'edit') { $result=$object->fetch($id); if ($result < 0) { dol_print_error($db,$object->error); exit; } $result=$object->fetch_optionals($object->id,$extralabels); if ($result < 0) { dol_print_error($db); exit; } $hselected='card'; $head = donation_prepare_head($object); print '
'; print ''; print ''; print ''; print ''; dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic'); print ''; // Ref print "".''; print ''; $nbrows=12; if (! empty($conf->projet->enabled)) $nbrows++; // Date print "".''; // Amount if ($object->statut == 0) { print "".''; } else { print ''; } print '"; print "\n"; $langs->load("companies"); print "".''; print "".''; print "".''; print "".''; // Zip / Town print ''; // Country print ''; print "".''; print "\n"; print "".''; // Project if (! empty($conf->projet->enabled)) { $formproject=new FormProjets($db); $langs->load('projects'); print ''; } // Other attributes $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit'); } print "
'.$langs->trans("Ref").''; print $object->getNomUrl(); print '
'.$langs->trans("Date").''; $form->select_date($object->date,'','','','',"update"); print '
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("Amount").''; print price($object->amount,0,$langs,0,0,-1,$conf->currency); print '
'.$langs->trans("PublicDonation").""; print $form->selectyesno("public",1,1); print "
'.$langs->trans("Company").'
'.$langs->trans("Lastname").'
'.$langs->trans("Firstname").'
'.$langs->trans("Address").''; print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6); print ' '; print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id')); print '
'.$langs->trans('Country').''; print $form->select_country((!empty($object->country_id)?$object->country_id:$mysoc->country_code),'country_id'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); print '
'.$langs->trans("EMail").'
".$langs->trans("PaymentMode")."\n"; if ($object->modepaymentid) $selected = $object->modepaymentid; else $selected = ''; $form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1); print "
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans('Project').''; $formproject->select_projects(-1, $object->fk_projet,'fk_projet', 0, 0, 1, 1); print '
\n"; dol_fiche_end(); print '
   
'; print "
\n"; } /* ************************************************************ */ /* */ /* Donation card in view mode */ /* */ /* ************************************************************ */ if (! empty($id) && $action != 'edit') { // Confirmation delete if ($action == 'delete') { $text=$langs->trans("ConfirmDeleteADonation"); print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("DeleteADonation"),$text,"confirm_delete",'','',1); } $result=$object->fetch($id); if ($result < 0) { dol_print_error($db,$object->error); exit; } $result=$object->fetch_optionals($object->id,$extralabels); if ($result < 0) { dol_print_error($db); exit; } $hselected='card'; $head = donation_prepare_head($object); dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic'); print '
'; print ''; print ''; $linkback = ''.$langs->trans("BackToList").''; $nbrows=12; if (! empty($conf->projet->enabled)) $nbrows++; // Ref print "".''; print ''; // Date print '"; print ''; print ''; print ''; print ''; print ''; print ''; $rowspan=6; if (! empty($conf->projet->enabled)) $rowspan++; print '"; print ""; // Zip / Town print ''; // Country print ''; // EMail print "".''; // Payment mode print "\n"; print "".''; // Project if (! empty($conf->projet->enabled)) { print ''; print ''; print ''; print ''; } // Other attributes $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields); } print "
'.$langs->trans("Ref").''; print $form->showrefnav($object, 'rowid', $linkback, 1, 'rowid', 'ref', ''); print '
'.$langs->trans("Date").''; print dol_print_date($object->date,"day"); print "
'.$langs->trans("Amount").''; print price($object->amount,0,$langs,0,0,-1,$conf->currency); print '
'.$langs->trans("PublicDonation").''; print yn($object->public); print '
'.$langs->trans("Company").''.$object->societe.'
'.$langs->trans("Lastname").''.$object->lastname.'
'.$langs->trans("Firstname").''.$object->firstname.'
'.$langs->trans("Address").''.dol_nl2br($object->address).''; /* * Payments */ $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,"; $sql.= "c.code as type_code,c.libelle as paiement_type"; $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 = '".$id."'"; $sql.= " AND p.fk_donation = d.rowid"; $sql.= " AND d.entity = ".$conf->entity; $sql.= " AND p.fk_typepayment = c.id"; $sql.= " ORDER BY dp"; //print $sql; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $total = 0; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $var=True; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print "'; print '\n"; $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->paiement_type; print "\n"; print '\n"; print ""; $totalpaid += $objp->amount; $i++; } if ($object->paid == 0) { print "\n"; print "\n"; $remaintopay = $object->amount - $totalpaid; print ""; print "\n"; } print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$labeltype.' '.$objp->num_payment."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaid)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("RemainderToPay")." :".price($remaintopay)." ".$langs->trans("Currency".$conf->currency)."
"; $db->free($resql); } else { dol_print_error($db); } print "
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; print $object->zip.($object->zip && $object->town?' / ':'').$object->town.'
'.$langs->trans('Country').''; if (! empty($object->country_code)) { $img=picto_from_langcode($object->country_code); print ($img?$img.' ':''); print $object->country; } else { print $object->country_olddata; } print '
'.$langs->trans("EMail").''.dol_print_email($object->email).'
".$langs->trans("PaymentMode").""; $form->form_modes_reglement(null, $object->modepaymentid,'none'); print "
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("Project").''; $projettmp=new Project($db); $projettmp->id=$object->fk_projet; $projettmp->ref=$object->project; print $projettmp->getNomUrl(1); print '
\n"; print "
\n"; print ""; $remaintopay = $object->amount - $totalpaid; /** * Actions buttons */ print '
'; print ''; if ($object->statut == 0) { print ''; } if (($object->statut == 0 || $object->statut == 1) && $remaintopay == 0 && $object->paye == 0) { print '"; } // Create payment if ($object->statut == 1 && $object->paid == 0 && $user->rights->don->creer) { if ($remaintopay == 0) { print '
' . $langs->trans('DoPayment') . '
'; } else { print ''; } } // Classify 'paid' if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer) { print '"; } // Delete if ($user->rights->don->supprimer) { if ($don->statut == -1 || $don->statut == 0) { print '"; } else { print '"; } } else { print '"; } print "
"; print ''; print '
'; /* * Documents generes */ $filename = dol_sanitizeFileName($object->id); $filedir = $conf->don->dir_output . "/" . dol_sanitizeFileName($object->id); $urlsource = $_SERVER['PHP_SELF'].'?rowid='.$object->id; $genallowed = ($object->statut == 2 && ($object->paid == 0 || $user->admin) && $user->rights->don->creer); $delallowed = $user->rights->don->supprimer; $var=true; print '
'; $formfile->show_documents('donation',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf); print '
 
'; } llxFooter(); $db->close();