card.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/payment_sc/card.php
  23. * \ingroup facture
  24. * \brief Onglet payment of a salary
  25. * \remarks Fichier presque identique a fournisseur/paiement/card.php
  26. */
  27. // Load Dolibarr environment
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  33. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('bills', 'banks', 'companies', 'salaries'));
  36. // Security check
  37. $id = GETPOST("id", 'int');
  38. $action = GETPOST('action', 'aZ09');
  39. $confirm = GETPOST('confirm');
  40. if ($user->socid) $socid = $user->socid;
  41. $object = new PaymentSalary($db);
  42. if ($id > 0) {
  43. $result = $object->fetch($id);
  44. if (!$result) dol_print_error($db, 'Failed to get payment id '.$id);
  45. }
  46. restrictedArea($user, 'salaries', $object->fk_salary, 'salary', ''); // $object is payment of salary
  47. /*
  48. * Actions
  49. */
  50. // Delete payment
  51. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->salaries->delete) {
  52. $db->begin();
  53. $result = $object->delete($user);
  54. if ($result > 0) {
  55. $db->commit();
  56. header("Location: ".DOL_URL_ROOT."/salaries/payments.php");
  57. exit;
  58. } else {
  59. setEventMessages($object->error, $object->errors, 'errors');
  60. $db->rollback();
  61. }
  62. }
  63. /*
  64. * View
  65. */
  66. llxHeader();
  67. $salary = new Salary($db);
  68. $form = new Form($db);
  69. $h = 0;
  70. $head = array();
  71. $head[$h][0] = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$id;
  72. $head[$h][1] = $langs->trans("SalaryPayment");
  73. $hselected = $h;
  74. $h++;
  75. /*
  76. $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
  77. $head[$h][1] = $langs->trans("Info");
  78. $h++;
  79. */
  80. print dol_get_fiche_head($head, $hselected, $langs->trans("SalaryPayment"), -1, 'payment');
  81. /*
  82. * Deletion confirmation of payment
  83. */
  84. if ($action == 'delete') {
  85. print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeleteSalary"), $langs->trans("ConfirmDeleteSalaryPayment"), 'confirm_delete', '', 0, 2);
  86. }
  87. /*
  88. * Validation confirmation of payment
  89. */
  90. /*
  91. if ($action == 'valide')
  92. {
  93. $facid = GETPOST('facid', 'int');
  94. print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
  95. }
  96. */
  97. $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/payments.php">'.$langs->trans("BackToList").'</a>';
  98. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
  99. print '<div class="fichecenter">';
  100. print '<div class="underbanner clearboth"></div>';
  101. print '<table class="border centpercent">';
  102. // Ref
  103. /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
  104. print '<td colspan="3">';
  105. print $form->showrefnav($object,'id','',1,'rowid','id');
  106. print '</td></tr>';*/
  107. // Date
  108. print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep, 'day').'</td></tr>';
  109. // Mode
  110. print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">';
  111. print $langs->trans("PaymentType".$object->type_code);
  112. print '</td></tr>';
  113. // Numero
  114. print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
  115. // Montant
  116. print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
  117. // Note
  118. print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
  119. // Bank account
  120. if (isModEnabled("banque")) {
  121. if ($object->bank_account) {
  122. $bankline = new AccountLine($db);
  123. $bankline->fetch($object->bank_line);
  124. print '<tr>';
  125. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  126. print '<td colspan="3">';
  127. print $bankline->getNomUrl(1, 0, 'showall');
  128. print '</td>';
  129. print '</tr>';
  130. }
  131. }
  132. print '</table>';
  133. print '</div>';
  134. print dol_get_fiche_end();
  135. /*
  136. * List of salaries payed
  137. */
  138. $disable_delete = 0;
  139. $sql = 'SELECT f.rowid as scid, f.label, f.paye, f.amount as sc_amount, ps.amount';
  140. $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps,'.MAIN_DB_PREFIX.'salary as f';
  141. $sql .= ' WHERE ps.fk_salary = f.rowid';
  142. $sql .= ' AND f.entity = '.$conf->entity;
  143. $sql .= ' AND ps.rowid = '.((int) $object->id);
  144. dol_syslog("payment_salary/card.php", LOG_DEBUG);
  145. $resql = $db->query($sql);
  146. if ($resql) {
  147. $num = $db->num_rows($resql);
  148. $i = 0;
  149. $total = 0;
  150. print '<br>';
  151. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  152. print '<table class="noborder centpercent">';
  153. print '<tr class="liste_titre">';
  154. print '<td>'.$langs->trans('Salary').'</td>';
  155. print '<td>'.$langs->trans('Label').'</td>';
  156. print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
  157. print '<td class="center">'.$langs->trans('Status').'</td>';
  158. print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
  159. print "</tr>\n";
  160. if ($num > 0) {
  161. while ($i < $num) {
  162. $objp = $db->fetch_object($resql);
  163. print '<tr class="oddeven">';
  164. // Ref
  165. print '<td>';
  166. $salary->fetch($objp->scid);
  167. print $salary->getNomUrl(1);
  168. print "</td>\n";
  169. // Label
  170. print '<td>'.$objp->label.'</td>';
  171. // Expected to pay
  172. print '<td class="right">'.price($objp->sc_amount).'</td>';
  173. // Status
  174. print '<td class="center">'.$salary->getLibStatut(4, $objp->amount).'</td>';
  175. // Amount payed
  176. print '<td class="right">'.price($objp->amount).'</td>';
  177. print "</tr>\n";
  178. if ($objp->paye == 1) {
  179. // If at least one invoice is paid, disable delete
  180. $disable_delete = 1;
  181. }
  182. $total = $total + $objp->amount;
  183. $i++;
  184. }
  185. }
  186. print "</table>\n";
  187. print "</div>";
  188. $db->free($resql);
  189. } else {
  190. dol_print_error($db);
  191. }
  192. /*
  193. * Button actions
  194. */
  195. print '<div class="tabsAction">';
  196. if ($action == '') {
  197. if ($user->rights->salaries->delete) {
  198. if (!$disable_delete) {
  199. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
  200. } else {
  201. print dolGetButtonAction($langs->trans("CantRemovePaymentSalaryPaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
  202. }
  203. }
  204. }
  205. print '</div>';
  206. // End of page
  207. llxFooter();
  208. $db->close();