PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/compta/payment_sc/fiche.php

https://github.com/asterix14/dolibarr
PHP | 329 lines | 193 code | 59 blank | 77 comment | 37 complexity | 682d87558ce6cd33cceec0d7f85c7942 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/payment_sc/fiche.php
  22. * \ingroup facture
  23. * \brief Onglet payment of a social contribution
  24. * \remarks Fichier presque identique a fournisseur/paiement/fiche.php
  25. */
  26. require('../../main.inc.php');
  27. require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/paymentsocialcontribution.class.php");
  29. require_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
  30. require_once(DOL_DOCUMENT_ROOT."/core/modules/facture/modules_facture.php");
  31. if ($conf->banque->enabled) require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
  32. $langs->load('bills');
  33. $langs->load('banks');
  34. $langs->load('companies');
  35. // Security check
  36. $id=isset($_GET["id"])?$_GET["id"]:$_POST["id"];
  37. $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
  38. if ($user->societe_id) $socid=$user->societe_id;
  39. // TODO ajouter regle pour restreindre acces paiement
  40. //$result = restrictedArea($user, 'facture', $id,'');
  41. $mesg='';
  42. /*
  43. * Actions
  44. */
  45. // Delete payment
  46. if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && $user->rights->tax->charges->supprimer)
  47. {
  48. $db->begin();
  49. $paiement = new PaymentSocialContribution($db);
  50. $paiement->fetch($_REQUEST['id']);
  51. $result = $paiement->delete($user);
  52. if ($result > 0)
  53. {
  54. $db->commit();
  55. Header("Location: ".DOL_URL_ROOT."/compta/charges/index.php?mode=sconly");
  56. exit;
  57. }
  58. else
  59. {
  60. $mesg='<div class="error">'.$paiement->error.'</div>';
  61. $db->rollback();
  62. }
  63. }
  64. // Create payment
  65. if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' && $user->rights->tax->charges->creer)
  66. {
  67. $db->begin();
  68. $paiement = new PaymentSocialContribution($db);
  69. $paiement->id = $_REQUEST['id'];
  70. if ($paiement->valide() > 0)
  71. {
  72. $db->commit();
  73. $factures=array(); // TODO Get all id of invoices linked to this payment
  74. foreach($factures as $id)
  75. {
  76. $fac = new Facture($db);
  77. $fac->fetch($id);
  78. $outputlangs = $langs;
  79. if (! empty($_REQUEST['lang_id']))
  80. {
  81. $outputlangs = new Translate("",$conf);
  82. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  83. }
  84. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $fac, '', $fac->modelpdf, $outputlangs, $hookmanager);
  85. }
  86. Header('Location: fiche.php?id='.$paiement->id);
  87. exit;
  88. }
  89. else
  90. {
  91. $mesg='<div class="error">'.$paiement->error.'</div>';
  92. $db->rollback();
  93. }
  94. }
  95. /*
  96. * View
  97. */
  98. llxHeader();
  99. $socialcontrib=new ChargeSociales($db);
  100. $paiement = new PaymentSocialContribution($db);
  101. $result=$paiement->fetch($_GET['id']);
  102. if ($result <= 0)
  103. {
  104. dol_print_error($db,'Payment '.$_GET['id'].' not found in database');
  105. exit;
  106. }
  107. $form = new Form($db);
  108. $h=0;
  109. $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='.$_GET["id"];
  110. $head[$h][1] = $langs->trans("Card");
  111. $hselected = $h;
  112. $h++;
  113. /*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$_GET["id"];
  114. $head[$h][1] = $langs->trans("Info");
  115. $h++;
  116. */
  117. dol_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribution"), 0, 'payment');
  118. /*
  119. * Confirmation de la suppression du paiement
  120. */
  121. if ($_GET['action'] == 'delete')
  122. {
  123. $ret=$form->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
  124. if ($ret == 'html') print '<br>';
  125. }
  126. /*
  127. * Confirmation de la validation du paiement
  128. */
  129. if ($_GET['action'] == 'valide')
  130. {
  131. $facid = $_GET['facid'];
  132. $ret=$form->form_confirm('fiche.php?id='.$paiement->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
  133. if ($ret == 'html') print '<br>';
  134. }
  135. if ($mesg) print $mesg.'<br>';
  136. print '<table class="border" width="100%">';
  137. // Ref
  138. print '<tr><td valign="top" width="140">'.$langs->trans('Ref').'</td>';
  139. print '<td colspan="3">';
  140. print $form->showrefnav($paiement,'id','',1,'rowid','id');
  141. print '</td></tr>';
  142. // Date
  143. print '<tr><td valign="top" width="120">'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($paiement->datep,'day').'</td></tr>';
  144. // Mode
  145. print '<tr><td valign="top">'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$paiement->type_code).'</td></tr>';
  146. // Numero
  147. print '<tr><td valign="top">'.$langs->trans('Numero').'</td><td colspan="3">'.$paiement->num_paiement.'</td></tr>';
  148. // Montant
  149. print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->amount).'&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
  150. // Note
  151. print '<tr><td valign="top">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($paiement->note).'</td></tr>';
  152. // Bank account
  153. if ($conf->banque->enabled)
  154. {
  155. if ($paiement->bank_account)
  156. {
  157. $bankline=new AccountLine($db);
  158. $bankline->fetch($paiement->bank_line);
  159. print '<tr>';
  160. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  161. print '<td colspan="3">';
  162. print $bankline->getNomUrl(1,0,'showall');
  163. print '</td>';
  164. print '</tr>';
  165. }
  166. }
  167. print '</table>';
  168. /*
  169. * List of social contributions payed
  170. */
  171. $disable_delete = 0;
  172. $sql = 'SELECT f.rowid as scid, f.libelle, f.paye, f.amount as sc_amount, pf.amount, pc.libelle as sc_type';
  173. $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementcharge as pf,'.MAIN_DB_PREFIX.'chargesociales as f, '.MAIN_DB_PREFIX.'c_chargesociales as pc';
  174. $sql.= ' WHERE pf.fk_charge = f.rowid AND f.fk_type = pc.id';
  175. $sql.= ' AND f.entity = '.$conf->entity;
  176. $sql.= ' AND pf.rowid = '.$paiement->id;
  177. dol_syslog("compta/payment_sc/fiche.php sql=".$sql);
  178. $resql=$db->query($sql);
  179. if ($resql)
  180. {
  181. $num = $db->num_rows($resql);
  182. $i = 0;
  183. $total = 0;
  184. print '<br><table class="noborder" width="100%">';
  185. print '<tr class="liste_titre">';
  186. print '<td>'.$langs->trans('SocialContribution').'</td>';
  187. print '<td>'.$langs->trans('Type').'</td>';
  188. print '<td>'.$langs->trans('Label').'</td>';
  189. print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
  190. print '<td align="center">'.$langs->trans('Status').'</td>';
  191. print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
  192. print "</tr>\n";
  193. if ($num > 0)
  194. {
  195. $var=True;
  196. while ($i < $num)
  197. {
  198. $objp = $db->fetch_object($resql);
  199. $var=!$var;
  200. print '<tr '.$bc[$var].'>';
  201. // Ref
  202. print '<td>';
  203. $socialcontrib->fetch($objp->scid);
  204. print $socialcontrib->getNomUrl(1);
  205. print "</td>\n";
  206. // Type
  207. print '<td>';
  208. print $socialcontrib->type_libelle;
  209. /*print $socialcontrib->type;*/
  210. print "</td>\n";
  211. // Label
  212. print '<td>'.$objp->libelle.'</td>';
  213. // Expected to pay
  214. print '<td align="right">'.price($objp->sc_amount).'</td>';
  215. // Status
  216. print '<td align="center">'.$socialcontrib->LibStatut($objp->fk_statut,2).'</td>';
  217. // Amount payed
  218. print '<td align="right">'.price($objp->amount).'</td>';
  219. print "</tr>\n";
  220. if ($objp->paye == 1) // If at least one invoice is paid, disable delete
  221. {
  222. $disable_delete = 1;
  223. }
  224. $total = $total + $objp->amount;
  225. $i++;
  226. }
  227. }
  228. $var=!$var;
  229. print "</table>\n";
  230. $db->free($resql);
  231. }
  232. else
  233. {
  234. dol_print_error($db);
  235. }
  236. print '</div>';
  237. /*
  238. * Boutons Actions
  239. */
  240. print '<div class="tabsAction">';
  241. /*
  242. if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
  243. {
  244. if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET['action'] == '')
  245. {
  246. if ($user->rights->facture->paiement)
  247. {
  248. print '<a class="butAction" href="fiche.php?id='.$_GET['id'].'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
  249. }
  250. }
  251. }
  252. */
  253. if ($_GET['action'] == '')
  254. {
  255. if ($user->rights->tax->charges->supprimer)
  256. {
  257. if (! $disable_delete)
  258. {
  259. print '<a class="butActionDelete" href="fiche.php?id='.$_GET['id'].'&amp;action=delete">'.$langs->trans('Delete').'</a>';
  260. }
  261. else
  262. {
  263. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
  264. }
  265. }
  266. }
  267. print '</div>';
  268. $db->close();
  269. llxFooter();
  270. ?>