card.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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/salaries/payment_salary/card.php
  23. * \ingroup salary
  24. * \brief Tab to pay a salary
  25. * \remarks File very similar with 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. $salary = new Salary($db);
  42. $object = new PaymentSalary($db);
  43. if ($id > 0) {
  44. $result = $object->fetch($id);
  45. if (!$result) dol_print_error($db, 'Failed to get payment id '.$id);
  46. }
  47. restrictedArea($user, 'salaries', $object->fk_salary, 'salary', ''); // $object is payment of salary
  48. /*
  49. * Actions
  50. */
  51. // Delete payment
  52. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('salaries', 'delete')) {
  53. $db->begin();
  54. $result = $object->delete($user);
  55. if ($result > 0) {
  56. $db->commit();
  57. header("Location: ".DOL_URL_ROOT."/salaries/payments.php");
  58. exit;
  59. } else {
  60. setEventMessages($object->error, $object->errors, 'errors');
  61. $db->rollback();
  62. }
  63. }
  64. if ($action == 'setdatep' && GETPOST('datepday') && $user->hasRight('salaries', 'write')) {
  65. $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'), 'tzuserrel');
  66. $res = $object->updatePaymentDate($datepaye);
  67. if ($res === 0) {
  68. setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
  69. } else {
  70. setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
  71. }
  72. }
  73. /*
  74. * View
  75. */
  76. $form = new Form($db);
  77. llxHeader('', $langs->trans("SalaryPayment"));
  78. $h = 0;
  79. $head = array();
  80. $head[$h][0] = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$id;
  81. $head[$h][1] = $langs->trans("SalaryPayment");
  82. $hselected = $h;
  83. $h++;
  84. /*
  85. $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
  86. $head[$h][1] = $langs->trans("Info");
  87. $h++;
  88. */
  89. print dol_get_fiche_head($head, $hselected, $langs->trans("SalaryPayment"), -1, 'payment');
  90. /*
  91. * Deletion confirmation of payment
  92. */
  93. if ($action == 'delete') {
  94. print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeleteSalary"), $langs->trans("ConfirmDeleteSalaryPayment"), 'confirm_delete', '', 0, 2);
  95. }
  96. /*
  97. * Validation confirmation of payment
  98. */
  99. /*
  100. if ($action == 'valide')
  101. {
  102. $facid = GETPOST('facid', 'int');
  103. print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
  104. }
  105. */
  106. $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/payments.php">'.$langs->trans("BackToList").'</a>';
  107. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
  108. print '<div class="fichecenter">';
  109. print '<div class="underbanner clearboth"></div>';
  110. print '<table class="border centpercent tableforfield">';
  111. // Ref
  112. /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
  113. print '<td colspan="3">';
  114. print $form->showrefnav($object,'id','',1,'rowid','id');
  115. print '</td></tr>';*/
  116. // Date
  117. print '<tr><td>';
  118. print $form->editfieldkey("Date", 'datep', $object->datep, $object, 1, 'datehourpicker');
  119. print '</td><td>';
  120. print $form->editfieldval("Date", 'datep', $object->datep, $object, 1, 'datehourpicker', '', null, null, '', 0, '', 'id', 'tzuserrel', array('addnowlink'=>1));
  121. print "</td>";
  122. print '</tr>';
  123. // Mode
  124. print '<tr><td>'.$langs->trans('Mode').'</td><td>';
  125. print $langs->trans("PaymentType".$object->type_code);
  126. print '</td></tr>';
  127. // Numero
  128. print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
  129. // Montant
  130. print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
  131. // Note
  132. print '<tr><td>'.$langs->trans('Note').'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_private)).'</td></tr>';
  133. // Bank account
  134. if (isModEnabled("banque")) {
  135. if ($object->bank_account) {
  136. $bankline = new AccountLine($db);
  137. $bankline->fetch($object->bank_line);
  138. print '<tr>';
  139. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  140. print '<td>';
  141. print $bankline->getNomUrl(1, 0, 'showall');
  142. print '</td>';
  143. print '</tr>';
  144. }
  145. }
  146. print '</table>';
  147. print '</div>';
  148. print dol_get_fiche_end();
  149. /*
  150. * List of salaries payed
  151. */
  152. $disable_delete = 0;
  153. $sql = 'SELECT f.rowid as scid, f.label, f.paye, f.amount as sc_amount, ps.amount';
  154. $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps,'.MAIN_DB_PREFIX.'salary as f';
  155. $sql .= ' WHERE ps.fk_salary = f.rowid';
  156. $sql .= ' AND f.entity = '.$conf->entity;
  157. $sql .= ' AND ps.rowid = '.((int) $object->id);
  158. dol_syslog("payment_salary/card.php", LOG_DEBUG);
  159. $resql = $db->query($sql);
  160. if ($resql) {
  161. $num = $db->num_rows($resql);
  162. $i = 0;
  163. $total = 0;
  164. print '<br>';
  165. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  166. print '<table class="noborder centpercent">';
  167. print '<tr class="liste_titre">';
  168. print '<td>'.$langs->trans('Salary').'</td>';
  169. print '<td>'.$langs->trans('Label').'</td>';
  170. print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
  171. print '<td class="center">'.$langs->trans('Status').'</td>';
  172. print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
  173. print "</tr>\n";
  174. if ($num > 0) {
  175. while ($i < $num) {
  176. $objp = $db->fetch_object($resql);
  177. print '<tr class="oddeven">';
  178. // Ref
  179. print '<td>';
  180. $salary->fetch($objp->scid);
  181. print $salary->getNomUrl(1);
  182. print "</td>\n";
  183. // Label
  184. print '<td>'.$objp->label.'</td>';
  185. // Expected to pay
  186. print '<td class="right">'.price($objp->sc_amount).'</td>';
  187. // Status
  188. print '<td class="center">'.$salary->getLibStatut(4, $objp->amount).'</td>';
  189. // Amount payed
  190. print '<td class="right">'.price($objp->amount).'</td>';
  191. print "</tr>\n";
  192. if ($objp->paye == 1) {
  193. // If at least one invoice is paid, disable delete
  194. $disable_delete = 1;
  195. }
  196. $total = $total + $objp->amount;
  197. $i++;
  198. }
  199. }
  200. print "</table>\n";
  201. print "</div>";
  202. $db->free($resql);
  203. } else {
  204. dol_print_error($db);
  205. }
  206. /*
  207. * Button actions
  208. */
  209. print '<div class="tabsAction">';
  210. if ($action == '') {
  211. if ($user->rights->salaries->delete) {
  212. if (!$disable_delete) {
  213. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
  214. } else {
  215. print dolGetButtonAction($langs->trans("CantRemovePaymentSalaryPaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
  216. }
  217. }
  218. }
  219. print '</div>';
  220. // End of page
  221. llxFooter();
  222. $db->close();