Update works

This commit is contained in:
aspangaro 2015-03-21 18:00:16 +01:00
parent 462e27e069
commit b4b3c45dbc
7 changed files with 353 additions and 25 deletions

View File

@ -6,7 +6,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@@2byte.es>
* Copyright (C) 2012-2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2011-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2011-2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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'];

View File

@ -526,10 +526,10 @@ if (! empty($id) && $action != 'edit')
print yn($object->public);
print '</td></tr>';
print "<tr>".'<td>'.$langs->trans("Company").'</td><td colspan="2">'.$object->societe.'</td></tr>';
print "<tr>".'<td>'.$langs->trans("Lastname").'</td><td colspan="2">'.$object->lastname.'</td></tr>';
print "<tr>".'<td>'.$langs->trans("Firstname").'</td><td colspan="2">'.$object->firstname.'</td></tr>';
print "<tr>".'<td>'.$langs->trans("Address").'</td><td>'.dol_nl2br($object->address).'</td>';
print '<tr><td>'.$langs->trans("Company").'</td><td colspan="2">'.$object->societe.'</td></tr>';
print '<tr><td>'.$langs->trans("Lastname").'</td><td colspan="2">'.$object->lastname.'</td></tr>';
print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="2">'.$object->firstname.'</td></tr>';
print '<tr><td>'.$langs->trans("Address").'</td><td>'.dol_nl2br($object->address).'</td>';
$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 "<tr ".$bc[$var]."><td>";
print '<a href="'.DOL_URL_ROOT.'/donations/payment.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
print '<a href="'.DOL_URL_ROOT.'/donations/payment/card.php?rowid='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
$labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->paiement_type;
print "<td>".$labeltype.' '.$object->num_paiement."</td>\n";
print '<td align="right">'.price($object->amount)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
print '<td align="right">'.price($objp->amount)."</td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td>\n";
print "</tr>";
$totalpaid += $object->amount;
$totalpaid += $objp->amount;
$i++;
}
if ($object->paid == 0)
{
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AlreadyPaid")." :</td><td align=\"right\"><b>".price($totalpaye)."</b></td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AlreadyPaid")." :</td><td align=\"right\"><b>".price($totalpaid)."</b></td><td>&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AmountExpected")." :</td><td align=\"right\" bgcolor=\"#d0d0d0\">".price($object->amount)."</td><td bgcolor=\"#d0d0d0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
$remaintopay = $object->amount - $totalpaid;
print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>";
print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($resteapayer)."</b></td><td bgcolor=\"#f0f0f0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($remaintopay)."</b></td><td bgcolor=\"#f0f0f0\">&nbsp;".$langs->trans("Currency".$conf->currency)."</td></tr>\n";
}
print "</table>";
$db->free($resql);
@ -679,7 +679,7 @@ if (! empty($id) && $action != 'edit')
}
else
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/donations/payment.php?rowid=' . $object->id . '&amp;action=create">' . $langs->trans('DoPayment') . '</a></div>';
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/donations/payment/payment.php?rowid=' . $object->id . '&amp;action=create">' . $langs->trans('DoPayment') . '</a></div>';
}
}

View File

@ -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");

View File

@ -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 = '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$link = '<a href="'.DOL_URL_ROOT.'/donations/payment/card.php?rowid='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend='</a>';
if ($withpicto) $result.=($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
@ -603,6 +603,4 @@ class PaymentDonation extends CommonObject
return $result;
}
}
}

View File

@ -0,0 +1,312 @@
<?php
/* Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \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.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
}
print '<table class="border" width="100%">';
// Ref
print '<tr><td valign="top" width="140">'.$langs->trans('Ref').'</td>';
print '<td colspan="3">';
print $form->showrefnav($payment,'id','',1,'rowid','id');
print '</td></tr>';
// Date
print '<tr><td valign="top" width="120">'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($payment->datep,'day').'</td></tr>';
// Mode
print '<tr><td valign="top">'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
// Number
print '<tr><td valign="top">'.$langs->trans('Number').'</td><td colspan="3">'.$payment->num_paiement.'</td></tr>';
// Amount
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($payment->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
// Note
print '<tr><td valign="top">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($payment->note).'</td></tr>';
// Bank account
if (! empty($conf->banque->enabled))
{
if ($payment->bank_account)
{
$bankline=new AccountLine($db);
$bankline->fetch($payment->bank_line);
print '<tr>';
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
print '<td colspan="3">';
print $bankline->getNomUrl(1,0,'showall');
print '</td>';
print '</tr>';
}
}
print '</table>';
/*
* 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 '<br><table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Donation').'</td>';
print '<td>'.$langs->trans('Type').'</td>';
print '<td>'.$langs->trans('Label').'</td>';
print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
print '<td align="center">'.$langs->trans('Status').'</td>';
print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
print "</tr>\n";
if ($num > 0)
{
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
$var=!$var;
print '<tr '.$bc[$var].'>';
// Ref
print '<td>';
$don->fetch($objp->did);
print $don->getNomUrl(1);
print "</td>\n";
// Type
print '<td>';
print $don->type_libelle;
/*print $don->type;*/
print "</td>\n";
// Label
print '<td>'.$objp->libelle.'</td>';
// Expected to pay
print '<td align="right">'.price($objp->d_amount).'</td>';
// Status
print '<td align="center">'.$don->getLibStatut(4,$objp->amount).'</td>';
// Amount payed
print '<td align="right">'.price($objp->amount).'</td>';
print "</tr>\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 "</table>\n";
$db->free($resql);
}
else
{
dol_print_error($db);
}
print '</div>';
/*
* Boutons Actions
*/
print '<div class="tabsAction">';
/*
if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
{
if ($user->societe_id == 0 && $payment->statut == 0 && $_GET['action'] == '')
{
if ($user->rights->facture->paiement)
{
print '<a class="butAction" href="card.php?id='.$_GET['id'].'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
}
}
}
*/
if ($_GET['action'] == '')
{
if ($user->rights->don->supprimer)
{
if (! $disable_delete)
{
print '<a class="butActionDelete" href="card.php?id='.$_GET['id'].'&amp;action=delete">'.$langs->trans('Delete').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
}
}
}
print '</div>';
llxFooter();
$db->close();

View File

View File

@ -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';