* Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2009 Regis Houssin * * 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/compta/payment_sc/card.php * \ingroup facture * \brief Onglet payment of a social contribution * \remarks Fichier presque identique a fournisseur/paiement/card.php */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.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 ajouter regle pour restreindre acces paiement //$result = restrictedArea($user, 'facture', $id,''); $paiement = new PaymentSocialContribution($db); if ($id > 0) { $result=$paiement->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->tax->charges->supprimer) { $db->begin(); $result = $paiement->delete($user); if ($result > 0) { $db->commit(); header("Location: ".DOL_URL_ROOT."/compta/charges/index.php?mode=sconly"); exit; } else { setEventMessage($paiement->error, 'errors'); $db->rollback(); } } // Create payment if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->tax->charges->creer) { $db->begin(); $result=$paiement->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='.$paiement->id); exit; } else { setEventMessage($paiement->error); $db->rollback(); } } /* * View */ llxHeader(); $socialcontrib=new ChargeSociales($db); $form = new Form($db); $h=0; $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("Card"); $hselected = $h; $h++; /*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("Info"); $h++; */ dol_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribution"), 0, 'payment'); /* * Confirmation de la suppression du paiement */ if ($action == 'delete') { print $form->formconfirm('card.php?id='.$paiement->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='.$paiement->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); } print ''; // Ref print ''; print ''; // Date print ''; // Mode print ''; // Numero print ''; // Montant print ''; // Note print ''; // Bank account if (! empty($conf->banque->enabled)) { if ($paiement->bank_account) { $bankline=new AccountLine($db); $bankline->fetch($paiement->bank_line); print ''; print ''; print ''; print ''; } } print '
'.$langs->trans('Ref').''; print $form->showrefnav($paiement,'id','',1,'rowid','id'); print '
'.$langs->trans('Date').''.dol_print_date($paiement->datep,'day').'
'.$langs->trans('Mode').''.$langs->trans("PaymentType".$paiement->type_code).'
'.$langs->trans('Numero').''.$paiement->num_paiement.'
'.$langs->trans('Amount').''.price($paiement->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Note').''.nl2br($paiement->note).'
'.$langs->trans('BankTransactionLine').''; print $bankline->getNomUrl(1,0,'showall'); print '
'; /* * List of social contributions payed */ $disable_delete = 0; $sql = 'SELECT f.rowid as scid, f.libelle, f.paye, f.amount as sc_amount, pf.amount, pc.libelle as sc_type'; $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementcharge as pf,'.MAIN_DB_PREFIX.'chargesociales as f, '.MAIN_DB_PREFIX.'c_chargesociales as pc'; $sql.= ' WHERE pf.fk_charge = f.rowid AND f.fk_type = pc.id'; $sql.= ' AND f.entity = '.$conf->entity; $sql.= ' AND pf.rowid = '.$paiement->id; dol_syslog("compta/payment_sc/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->paye == 1) // If at least one invoice is paid, disable delete { $disable_delete = 1; } $total = $total + $objp->amount; $i++; } } $var=!$var; print "
'.$langs->trans('SocialContribution').''.$langs->trans('Type').''.$langs->trans('Label').''.$langs->trans('ExpectedToPay').''.$langs->trans('Status').''.$langs->trans('PayedByThisPayment').'
'; $socialcontrib->fetch($objp->scid); print $socialcontrib->getNomUrl(1); print "'; print $socialcontrib->type_libelle; /*print $socialcontrib->type;*/ print "'.$objp->libelle.''.price($objp->sc_amount).''.$socialcontrib->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 && $paiement->statut == 0 && $_GET['action'] == '') { if ($user->rights->facture->paiement) { print ''.$langs->trans('Valid').''; } } } */ if ($_GET['action'] == '') { if ($user->rights->tax->charges->supprimer) { if (! $disable_delete) { print ''.$langs->trans('Delete').''; } else { print ''.$langs->trans('Delete').''; } } } print '
'; llxFooter(); $db->close();