card.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  1. <?php
  2. /* Copyright (C) 2011-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2014-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  5. * Copyright (C) 2015 Charlie BENKE <charlie@patas-monkey.com>
  6. * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
  7. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/salaries/card.php
  24. * \ingroup salaries
  25. * \brief Page of salaries payments
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  37. if (isModEnabled('project')) {
  38. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  40. }
  41. // Load translation files required by the page
  42. $langs->loadLangs(array("compta", "banks", "bills", "users", "salaries", "hrm", "trips"));
  43. if (isModEnabled('project')) {
  44. $langs->load("projects");
  45. }
  46. $id = GETPOSTINT('id');
  47. $ref = GETPOST('ref', 'alpha');
  48. $action = GETPOST('action', 'aZ09');
  49. $cancel = GETPOST('cancel', 'aZ09');
  50. $backtopage = GETPOST('backtopage', 'alpha');
  51. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  52. $confirm = GETPOST('confirm');
  53. $label = GETPOST('label', 'alphanohtml');
  54. $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int'));
  55. $accountid = GETPOST('accountid', 'int') > 0 ? GETPOST('accountid', 'int') : 0;
  56. if (GETPOSTISSET('auto_create_paiement') || $action === 'add') {
  57. $auto_create_paiement = GETPOST("auto_create_paiement", "int");
  58. } else {
  59. $auto_create_paiement = empty($conf->global->CREATE_NEW_SALARY_WITHOUT_AUTO_PAYMENT);
  60. }
  61. $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int'));
  62. $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int'));
  63. $datesp = dol_mktime(12, 0, 0, GETPOST("datespmonth", 'int'), GETPOST("datespday", 'int'), GETPOST("datespyear", 'int'));
  64. $dateep = dol_mktime(12, 0, 0, GETPOST("dateepmonth", 'int'), GETPOST("dateepday", 'int'), GETPOST("dateepyear", 'int'));
  65. $fk_user = GETPOSTINT('userid');
  66. $object = new Salary($db);
  67. $extrafields = new ExtraFields($db);
  68. $childids = $user->getAllChildIds(1);
  69. // fetch optionals attributes and labels
  70. $extrafields->fetch_name_optionals_label($object->table_element);
  71. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  72. $hookmanager->initHooks(array('salarycard', 'globalcard'));
  73. if ($id > 0 || !empty($ref)) {
  74. $object->fetch($id, $ref);
  75. // Check current user can read this salary
  76. $canread = 0;
  77. if (!empty($user->rights->salaries->readall)) {
  78. $canread = 1;
  79. }
  80. if (!empty($user->rights->salaries->read) && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
  81. $canread = 1;
  82. }
  83. if (!$canread) {
  84. accessforbidden();
  85. }
  86. }
  87. // Security check
  88. $socid = GETPOSTINT('socid');
  89. if ($user->socid) {
  90. $socid = $user->socid;
  91. }
  92. restrictedArea($user, 'salaries', $object->id, 'salary', '');
  93. $permissiontoread = $user->rights->salaries->read;
  94. $permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  95. $permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  96. /*
  97. * Actions
  98. */
  99. $parameters = array();
  100. // Note that $action and $object may be modified by some hooks
  101. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
  102. if ($reshook < 0) {
  103. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  104. }
  105. if (empty($reshook)) {
  106. $error = 0;
  107. $backurlforlist = DOL_URL_ROOT.'/salaries/list.php';
  108. if (empty($backtopage) || ($cancel && empty($id))) {
  109. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  110. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  111. $backtopage = $backurlforlist;
  112. } else {
  113. $backtopage = DOL_URL_ROOT.'/salaries/card.php?id='.($id > 0 ? $id : '__ID__');
  114. }
  115. }
  116. }
  117. if ($cancel) {
  118. //var_dump($cancel);
  119. //var_dump($backtopage);exit;
  120. if (!empty($backtopageforcancel)) {
  121. header("Location: ".$backtopageforcancel);
  122. exit;
  123. } elseif (!empty($backtopage)) {
  124. header("Location: ".$backtopage);
  125. exit;
  126. }
  127. $action = '';
  128. }
  129. }
  130. // Link to a project
  131. if ($action == 'classin' && $user->rights->banque->modifier) {
  132. $object->fetch($id);
  133. $object->setProject($projectid);
  134. }
  135. // set label
  136. if ($action == 'setlabel' && $user->rights->salaries->write) {
  137. $object->fetch($id);
  138. $object->label = $label;
  139. $object->update($user);
  140. }
  141. // Classify paid
  142. if ($action == 'confirm_paid' && $user->rights->salaries->write && $confirm == 'yes') {
  143. $object->fetch($id);
  144. $result = $object->set_paid($user);
  145. }
  146. if ($action == 'setfk_user' && $user->rights->salaries->write) {
  147. $result = $object->fetch($id);
  148. if ($result > 0) {
  149. $object->fk_user = $fk_user;
  150. $object->update($user);
  151. } else {
  152. dol_print_error($db);
  153. exit;
  154. }
  155. }
  156. if ($action == 'reopen' && $user->rights->salaries->write) {
  157. $result = $object->fetch($id);
  158. if ($object->paye) {
  159. $result = $object->set_unpaid($user);
  160. if ($result > 0) {
  161. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  162. exit();
  163. } else {
  164. setEventMessages($object->error, $object->errors, 'errors');
  165. }
  166. }
  167. }
  168. // payment mode
  169. if ($action == 'setmode' && $user->rights->salaries->write) {
  170. $object->fetch($id);
  171. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
  172. if ($result < 0)
  173. setEventMessages($object->error, $object->errors, 'errors');
  174. }
  175. // bank account
  176. if ($action == 'setbankaccount' && $user->rights->salaries->write) {
  177. $object->fetch($id);
  178. $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
  179. if ($result < 0) {
  180. setEventMessages($object->error, $object->errors, 'errors');
  181. }
  182. }
  183. if ($action == 'add' && empty($cancel)) {
  184. $error = 0;
  185. if (empty($datev)) $datev = $datep;
  186. $type_payment = GETPOST("paymenttype", 'alpha');
  187. $amount = price2num(GETPOST("amount", 'alpha'), 'MT', 2);
  188. $object->accountid = GETPOST("accountid", 'int') > 0 ? GETPOST("accountid", "int") : 0;
  189. $object->fk_user = GETPOST("fk_user", 'int') > 0 ? GETPOST("fk_user", "int") : 0;
  190. $object->datev = $datev;
  191. $object->datep = $datep;
  192. $object->amount = $amount;
  193. $object->label = GETPOST("label", 'alphanohtml');
  194. $object->datesp = $datesp;
  195. $object->dateep = $dateep;
  196. $object->note = GETPOST("note", 'restricthtml');
  197. $object->type_payment = ($type_payment > 0 ? $type_payment : 0);
  198. $object->fk_user_author = $user->id;
  199. $object->fk_project = $projectid;
  200. // Set user current salary as ref salary for the payment
  201. $fuser = new User($db);
  202. $fuser->fetch(GETPOST("fk_user", "int"));
  203. $object->salary = $fuser->salary;
  204. // Fill array 'array_options' with data from add form
  205. $ret = $extrafields->setOptionalsFromPost(null, $object);
  206. if ($ret < 0) {
  207. $error++;
  208. }
  209. if (!empty($auto_create_paiement) && empty($datep)) {
  210. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DATE_PAIEMENT")), null, 'errors');
  211. $error++;
  212. }
  213. if (empty($datesp) || empty($dateep)) {
  214. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  215. $error++;
  216. }
  217. if (empty($object->fk_user) || $object->fk_user < 0) {
  218. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Employee")), null, 'errors');
  219. $error++;
  220. }
  221. if (!empty($auto_create_paiement) && (empty($type_payment) || $type_payment < 0)) {
  222. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
  223. $error++;
  224. }
  225. if (empty($object->amount)) {
  226. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
  227. $error++;
  228. }
  229. if (isModEnabled("banque") && !empty($auto_create_paiement) && !$object->accountid > 0) {
  230. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
  231. $error++;
  232. }
  233. if (!$error) {
  234. $db->begin();
  235. $ret = $object->create($user);
  236. if ($ret < 0) {
  237. setEventMessages($object->error, $object->errors, 'errors');
  238. $error++;
  239. }
  240. if (!empty($auto_create_paiement) && !$error) {
  241. // Create a line of payments
  242. $paiement = new PaymentSalary($db);
  243. $paiement->chid = $object->id;
  244. $paiement->datepaye = $datep;
  245. $paiement->datev = $datev;
  246. $paiement->amounts = array($object->id=>$amount); // Tableau de montant
  247. $paiement->paiementtype = $type_payment;
  248. $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
  249. $paiement->note = GETPOST("note", 'restricthtml');
  250. if (!$error) {
  251. $paymentid = $paiement->create($user, (int) GETPOST('closepaidsalary'));
  252. if ($paymentid < 0) {
  253. $error++;
  254. setEventMessages($paiement->error, null, 'errors');
  255. $action = 'create';
  256. }
  257. }
  258. if (!$error) {
  259. $result = $paiement->addPaymentToBank($user, 'payment_salary', '(SalaryPayment)', GETPOST('accountid', 'int'), '', '');
  260. if (!($result > 0)) {
  261. $error++;
  262. setEventMessages($paiement->error, null, 'errors');
  263. }
  264. }
  265. }
  266. if (empty($error)) {
  267. $db->commit();
  268. if (GETPOST('saveandnew', 'alpha')) {
  269. setEventMessages($langs->trans("RecordSaved"), '', 'mesgs');
  270. header("Location: card.php?action=create&fk_project=" . urlencode($projectid) . "&accountid=" . urlencode($accountid) . '&paymenttype=' . urlencode(GETPOST('paymenttype', 'az09')) . '&datepday=' . GETPOST("datepday", 'int') . '&datepmonth=' . GETPOST("datepmonth", 'int') . '&datepyear=' . GETPOST("datepyear", 'int'));
  271. exit;
  272. } else {
  273. header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $object->id);
  274. exit;
  275. }
  276. } else {
  277. $db->rollback();
  278. }
  279. }
  280. $action = 'create';
  281. }
  282. if ($action == 'confirm_delete') {
  283. $result = $object->fetch($id);
  284. $totalpaid = $object->getSommePaiement();
  285. if (empty($totalpaid)) {
  286. $db->begin();
  287. $ret = $object->delete($user);
  288. if ($ret > 0) {
  289. $db->commit();
  290. header("Location: ".DOL_URL_ROOT.'/salaries/list.php');
  291. exit;
  292. } else {
  293. $db->rollback();
  294. setEventMessages($object->error, $object->errors, 'errors');
  295. }
  296. } else {
  297. setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
  298. }
  299. }
  300. if ($action == 'update' && !GETPOST("cancel") && $user->rights->salaries->write) {
  301. $amount = price2num(GETPOST('amount'), 'MT', 2);
  302. if (empty($amount)) {
  303. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
  304. $action = 'edit';
  305. } elseif (!is_numeric($amount)) {
  306. setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
  307. $action = 'create';
  308. } else {
  309. $result = $object->fetch($id);
  310. $object->amount = price2num($amount);
  311. $object->datesp = price2num($datesp);
  312. $object->dateep = price2num($dateep);
  313. $result = $object->update($user);
  314. if ($result <= 0) {
  315. setEventMessages($object->error, $object->errors, 'errors');
  316. }
  317. }
  318. }
  319. if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; }
  320. if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->salaries->write)) {
  321. $db->begin();
  322. $originalId = $id;
  323. $object->fetch($id);
  324. if ($object->id > 0) {
  325. $object->paye = 0;
  326. $object->id = $object->ref = null;
  327. if (GETPOST('clone_label', 'alphanohtml')) {
  328. $object->label = GETPOST('clone_label', 'alphanohtml');
  329. } else {
  330. $object->label = $langs->trans("CopyOf").' '.$object->label;
  331. }
  332. $newdatestart = dol_mktime(0, 0, 0, GETPOST('clone_date_startmonth', 'int'), GETPOST('clone_date_startday', 'int'), GETPOST('clone_date_startyear', 'int'));
  333. $newdateend = dol_mktime(0, 0, 0, GETPOST('clone_date_endmonth', 'int'), GETPOST('clone_date_endday', 'int'), GETPOST('clone_date_endyear', 'int'));
  334. if ($newdatestart) $object->datesp = $newdatestart;
  335. if ($newdateend) $object->dateep = $newdateend;
  336. $id = $object->create($user);
  337. if ($id > 0) {
  338. $db->commit();
  339. $db->close();
  340. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  341. exit;
  342. } else {
  343. $id = $originalId;
  344. $db->rollback();
  345. setEventMessages($object->error, $object->errors, 'errors');
  346. }
  347. } else {
  348. $db->rollback();
  349. dol_print_error($db, $object->error);
  350. }
  351. }
  352. // Action to update one extrafield
  353. if ($action == "update_extras" && !empty($user->rights->salaries->read)) {
  354. $object->fetch(GETPOST('id', 'int'));
  355. $attributekey = GETPOST('attribute', 'alpha');
  356. $attributekeylong = 'options_'.$attributekey;
  357. if (GETPOSTISSET($attributekeylong.'day') && GETPOSTISSET($attributekeylong.'month') && GETPOSTISSET($attributekeylong.'year')) {
  358. // This is properties of a date
  359. $object->array_options['options_'.$attributekey] = dol_mktime(GETPOST($attributekeylong.'hour', 'int'), GETPOST($attributekeylong.'min', 'int'), GETPOST($attributekeylong.'sec', 'int'), GETPOST($attributekeylong.'month', 'int'), GETPOST($attributekeylong.'day', 'int'), GETPOST($attributekeylong.'year', 'int'));
  360. //var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit;
  361. } else {
  362. $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, 'alpha');
  363. }
  364. $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
  365. if ($result > 0) {
  366. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  367. $action = 'view';
  368. } else {
  369. setEventMessages($object->error, $object->errors, 'errors');
  370. $action = 'edit_extras';
  371. }
  372. }
  373. /*
  374. * View
  375. */
  376. $form = new Form($db);
  377. $formfile = new FormFile($db);
  378. if (isModEnabled('project')) $formproject = new FormProjets($db);
  379. $title = $langs->trans('Salary')." - ".$object->ref;
  380. $help_url = "";
  381. llxHeader('', $title, $help_url);
  382. if ($id > 0) {
  383. $result = $object->fetch($id);
  384. if ($result <= 0) {
  385. dol_print_error($db);
  386. exit;
  387. }
  388. }
  389. // Create
  390. if ($action == 'create' && $permissiontoadd) {
  391. $year_current = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
  392. $pastmonth = strftime("%m", dol_now()) - 1;
  393. $pastmonthyear = $year_current;
  394. if ($pastmonth == 0) {
  395. $pastmonth = 12;
  396. $pastmonthyear--;
  397. }
  398. $datespmonth = GETPOST('datespmonth', 'int');
  399. $datespday = GETPOST('datespday', 'int');
  400. $datespyear = GETPOST('datespyear', 'int');
  401. $dateepmonth = GETPOST('dateepmonth', 'int');
  402. $dateepday = GETPOST('dateepday', 'int');
  403. $dateepyear = GETPOST('dateepyear', 'int');
  404. $datesp = dol_mktime(0, 0, 0, $datespmonth, $datespday, $datespyear);
  405. $dateep = dol_mktime(23, 59, 59, $dateepmonth, $dateepday, $dateepyear);
  406. if (empty($datesp) || empty($dateep)) { // We define date_start and date_end
  407. $datesp = dol_get_first_day($pastmonthyear, $pastmonth, false); $dateep = dol_get_last_day($pastmonthyear, $pastmonth, false);
  408. }
  409. print '<form name="salary" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  410. print '<input type="hidden" name="token" value="'.newToken().'">';
  411. print '<input type="hidden" name="action" value="add">';
  412. if ($backtopage) {
  413. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  414. }
  415. if ($backtopageforcancel) {
  416. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  417. }
  418. print load_fiche_titre($langs->trans("NewSalary"), '', 'salary');
  419. if (!empty($conf->use_javascript_ajax)) {
  420. print "\n".'<script type="text/javascript">';
  421. print /** @lang JavaScript */'
  422. $(document).ready(function () {
  423. let onAutoCreatePaiementChange = function () {
  424. if($("#auto_create_paiement").is(":checked")) {
  425. $("#label_fk_account").find("span").addClass("fieldrequired");
  426. $("#label_type_payment").find("span").addClass("fieldrequired");
  427. $(".hide_if_no_auto_create_payment").show();
  428. } else {
  429. $("#label_fk_account").find("span").removeClass("fieldrequired");
  430. $("#label_type_payment").find("span").removeClass("fieldrequired");
  431. $(".hide_if_no_auto_create_payment").hide();
  432. }
  433. };
  434. $("#radiopayment").click(function() {
  435. $("#label").val($(this).data("label"));
  436. });
  437. $("#radiorefund").click(function() {
  438. $("#label").val($(this).data("label"));
  439. });
  440. $("#auto_create_paiement").click(function () {
  441. onAutoCreatePaiementChange();
  442. });
  443. onAutoCreatePaiementChange();
  444. });
  445. ';
  446. print '</script>'."\n";
  447. }
  448. print dol_get_fiche_head('');
  449. print '<table class="border centpercent">';
  450. // Employee
  451. print '<tr><td class="titlefieldcreate">';
  452. print $form->editfieldkey('Employee', 'fk_user', '', $object, 0, 'string', '', 1).'</td><td>';
  453. $noactive = 0; // We keep active and unactive users
  454. print img_picto('', 'user', 'class="paddingrighonly"').$form->select_dolusers(GETPOST('fk_user', 'int'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, 'AND employee=1', 0, '', 'maxwidth300', $noactive);
  455. print '</td></tr>';
  456. // Label
  457. print '<tr><td>';
  458. print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
  459. print '<input name="label" id="label" class="minwidth300" value="'.(GETPOST("label") ?GETPOST("label") : $langs->trans("Salary")).'">';
  460. print '</td></tr>';
  461. // Date start period
  462. print '<tr><td>';
  463. print $form->editfieldkey('DateStartPeriod', 'datesp', '', $object, 0, 'string', '', 1).'</td><td>';
  464. print $form->selectDate($datesp, "datesp", '', '', '', 'add');
  465. print '</td></tr>';
  466. // Date end period
  467. print '<tr><td>';
  468. print $form->editfieldkey('DateEndPeriod', 'dateep', '', $object, 0, 'string', '', 1).'</td><td>';
  469. print $form->selectDate($dateep, "dateep", '', '', '', 'add');
  470. print '</td></tr>';
  471. // Amount
  472. print '<tr><td>';
  473. print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
  474. print '<input name="amount" id="amount" class="minwidth75 maxwidth100" value="'.GETPOST("amount").'">&nbsp;';
  475. print '<button class="dpInvisibleButtons datenow" id="updateAmountWithLastSalary" name="_useless" type="button">'.$langs->trans('UpdateAmountWithLastSalary').'</a>';
  476. print '</td>';
  477. print '</tr>';
  478. // Project
  479. if (isModEnabled('project')) {
  480. $formproject = new FormProjets($db);
  481. print '<tr><td>'.$langs->trans("Project").'</td><td>';
  482. print img_picto('', 'project', 'class="pictofixedwidth"');
  483. print $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
  484. print '</td></tr>';
  485. }
  486. // Comments
  487. print '<tr>';
  488. print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
  489. print '<td class="tdtop"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.'">'.GETPOST('note', 'restricthtml').'</textarea></td>';
  490. print '</tr>';
  491. print '<tr><td colspan="2"><hr></td></tr>';
  492. // Auto create payment
  493. print '<tr><td><label for="auto_create_paiement">'.$langs->trans('AutomaticCreationPayment').'</label></td>';
  494. print '<td><input id="auto_create_paiement" name="auto_create_paiement" type="checkbox" ' . (empty($auto_create_paiement) ? '' : 'checked="checked"') . ' value="1"></td></tr>'."\n"; // Date payment
  495. // Bank
  496. if (isModEnabled("banque")) {
  497. print '<tr><td id="label_fk_account">';
  498. print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
  499. print img_picto('', 'bank_account', 'class="paddingrighonly"');
  500. $form->select_comptes($accountid, "accountid", 0, '', 1); // Affiche liste des comptes courant
  501. print '</td></tr>';
  502. }
  503. // Type payment
  504. print '<tr><td id="label_type_payment">';
  505. print $form->editfieldkey('PaymentMode', 'selectpaymenttype', '', $object, 0, 'string', '', 1).'</td><td>';
  506. $form->select_types_paiements(GETPOST("paymenttype", 'aZ09'), "paymenttype", '');
  507. print '</td></tr>';
  508. // Date payment
  509. print '<tr class="hide_if_no_auto_create_payment"><td>';
  510. print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
  511. print $form->selectDate((empty($datep) ? '' : $datep), "datep", 0, 0, 0, 'add', 1, 1);
  512. print '</td></tr>';
  513. // Date value for bank
  514. print '<tr class="hide_if_no_auto_create_payment"><td>';
  515. print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
  516. print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1);
  517. print '</td></tr>';
  518. // Number
  519. if (isModEnabled("banque")) {
  520. // Number
  521. print '<tr class="hide_if_no_auto_create_payment"><td><label for="num_payment">'.$langs->trans('Numero');
  522. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  523. print '</label></td>';
  524. print '<td><input name="num_payment" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
  525. }
  526. // Bouton Save payment
  527. /*
  528. print '<tr class="hide_if_no_auto_create_payment"><td>';
  529. print $langs->trans("ClosePaidSalaryAutomatically");
  530. print '</td><td><input type="checkbox" checked value="1" name="closepaidsalary"></td></tr>';
  531. */
  532. // Other attributes
  533. $parameters = array();
  534. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  535. print $hookmanager->resPrint;
  536. if (empty($reshook)) {
  537. print $object->showOptionals($extrafields, 'create');
  538. }
  539. print '</table>';
  540. print dol_get_fiche_end();
  541. print '<div class="center">';
  542. print '<div class="hide_if_no_auto_create_payment paddingbottom">';
  543. print '<input type="checkbox" checked value="1" name="closepaidsalary">'.$langs->trans("ClosePaidSalaryAutomatically");
  544. print '</div>';
  545. print '</div>';
  546. $addition_button = array(
  547. 'name' => 'saveandnew',
  548. 'label_key' => 'SaveAndNew',
  549. );
  550. print $form->buttonsSaveCancel("Save", "Cancel", $addition_button);
  551. print '</form>';
  552. print '<script>';
  553. print '$( document ).ready(function() {';
  554. print '$("#updateAmountWithLastSalary").on("click", function updateAmountWithLastSalary() {
  555. var fk_user = $("#fk_user").val()
  556. var url = "'.DOL_URL_ROOT.'/salaries/ajax/ajaxsalaries.php?fk_user="+fk_user;
  557. console.log("We click on link to autofill salary amount url="+url);
  558. if (fk_user != -1) {
  559. $.get(
  560. url,
  561. function( data ) {
  562. console.log("Data returned: "+data);
  563. if (data != null) {
  564. if (typeof data == "object") {
  565. console.log("data is already type object, no need to parse it");
  566. item = data;
  567. } else {
  568. console.log("data is type "+(typeof data));
  569. item = JSON.parse(data);
  570. }
  571. if (item[0].key == "Amount") {
  572. value = item[0].value;
  573. console.log("amount returned = "+value);
  574. if (value != null) {
  575. $("#amount").val(item[0].value);
  576. } else {
  577. console.error("Error: Ajax url "+url+" has returned a null value.");
  578. }
  579. } else {
  580. console.error("Error: Ajax url "+url+" has returned the wrong key.");
  581. }
  582. } else {
  583. console.error("Error: Ajax url "+url+" has returned an empty page.");
  584. }
  585. }
  586. );
  587. } else {
  588. alert("'.dol_escape_js($langs->transnoentitiesnoconv("FillFieldFirst")).'");
  589. }
  590. });
  591. })';
  592. print '</script>';
  593. }
  594. // View mode
  595. if ($id > 0) {
  596. $head = salaries_prepare_head($object);
  597. $formconfirm = '';
  598. if ($action === 'clone') {
  599. $formquestion = array(
  600. array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
  601. );
  602. //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
  603. $formquestion[] = array('type' => 'date', 'name' => 'clone_date_start', 'label' => $langs->trans("DateStart"), 'value' => -1);
  604. $formquestion[] = array('type' => 'date', 'name' => 'clone_date_end', 'label' => $langs->trans("DateEnd"), 'value' => -1);
  605. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneSalary', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 250);
  606. }
  607. if ($action == 'paid') {
  608. $text = $langs->trans('ConfirmPaySalary');
  609. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySalary'), $text, "confirm_paid", '', '', 2);
  610. }
  611. if ($action == 'delete') {
  612. $text = $langs->trans('ConfirmDeleteSalary');
  613. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSalary'), $text, 'confirm_delete', '', '', 2);
  614. }
  615. if ($action == 'edit') {
  616. print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
  617. print '<input type="hidden" name="token" value="'.newToken().'">';
  618. }
  619. // Call Hook formConfirm
  620. $parameters = array('formConfirm' => $formconfirm);
  621. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  622. if (empty($reshook)) {
  623. $formconfirm .= $hookmanager->resPrint;
  624. } elseif ($reshook > 0) {
  625. $formconfirm = $hookmanager->resPrint;
  626. }
  627. // Print form confirm
  628. print $formconfirm;
  629. print dol_get_fiche_head($head, 'card', $langs->trans("SalaryPayment"), -1, 'salary');
  630. $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  631. $morehtmlref = '<div class="refidno">';
  632. // Label
  633. if ($action != 'editlabel') {
  634. $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
  635. $morehtmlref .= $object->label;
  636. } else {
  637. $morehtmlref .= $langs->trans('Label').' :&nbsp;';
  638. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  639. $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
  640. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  641. $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
  642. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  643. $morehtmlref .= '</form>';
  644. }
  645. // Employee
  646. if ($action != 'editfk_user') {
  647. if ($object->getSommePaiement() > 0 && !empty($object->fk_user)) {
  648. $userstatic = new User($db);
  649. $result = $userstatic->fetch($object->fk_user);
  650. if ($result > 0) {
  651. $morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
  652. }
  653. } else {
  654. $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
  655. if (!empty($object->fk_user)) {
  656. $userstatic = new User($db);
  657. $result = $userstatic->fetch($object->fk_user);
  658. if ($result > 0) {
  659. $morehtmlref .= $userstatic->getNomUrl(-1);
  660. } else {
  661. dol_print_error($db);
  662. exit();
  663. }
  664. }
  665. }
  666. } else {
  667. $morehtmlref .= '<br>'.$langs->trans('Employee').' :&nbsp;';
  668. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  669. $morehtmlref .= '<input type="hidden" name="action" value="setfk_user">';
  670. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  671. $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1);
  672. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  673. $morehtmlref .= '</form>';
  674. }
  675. $usercancreate = $permissiontoadd;
  676. // Project
  677. if (isModEnabled('project')) {
  678. $langs->load("projects");
  679. $morehtmlref .= '<br>';
  680. if ($usercancreate) {
  681. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  682. if ($action != 'classify') {
  683. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  684. }
  685. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  686. } else {
  687. if (!empty($object->fk_project)) {
  688. $proj = new Project($db);
  689. $proj->fetch($object->fk_project);
  690. $morehtmlref .= $proj->getNomUrl(1);
  691. if ($proj->title) {
  692. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  693. }
  694. }
  695. }
  696. }
  697. $morehtmlref .= '</div>';
  698. $totalpaid = $object->getSommePaiement();
  699. $object->totalpaid = $totalpaid;
  700. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
  701. print '<div class="fichecenter">';
  702. print '<div class="fichehalfleft">';
  703. print '<div class="underbanner clearboth"></div>';
  704. print '<table class="border centpercent tableforfield">';
  705. if ($action == 'edit') {
  706. print '<tr><td class="titlefield">'.$langs->trans("DateStartPeriod")."</td><td>";
  707. print $form->selectDate($object->datesp, 'datesp', 0, 0, 0, 'datesp', 1);
  708. print "</td></tr>";
  709. } else {
  710. print "<tr>";
  711. print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
  712. print dol_print_date($object->datesp, 'day');
  713. print '</td></tr>';
  714. }
  715. if ($action == 'edit') {
  716. print '<tr><td>'.$langs->trans("DateEndPeriod")."</td><td>";
  717. print $form->selectDate($object->dateep, 'dateep', 0, 0, 0, 'dateep', 1);
  718. print "</td></tr>";
  719. } else {
  720. print "<tr>";
  721. print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
  722. print dol_print_date($object->dateep, 'day');
  723. print '</td></tr>';
  724. }
  725. /*print "<tr>";
  726. print '<td>'.$langs->trans("DatePayment").'</td><td>';
  727. print dol_print_date($object->datep, 'day');
  728. print '</td></tr>';
  729. print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
  730. print dol_print_date($object->datev, 'day');
  731. print '</td></tr>';*/
  732. if ($action == 'edit') {
  733. print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
  734. } else {
  735. print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
  736. }
  737. // Default mode of payment
  738. print '<tr><td>';
  739. print '<table class="nobordernopadding" width="100%"><tr><td>';
  740. print $langs->trans('DefaultPaymentMode');
  741. print '</td>';
  742. if ($action != 'editmode')
  743. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
  744. print '</tr></table>';
  745. print '</td><td>';
  746. if ($action == 'editmode') {
  747. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
  748. } else {
  749. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
  750. }
  751. print '</td></tr>';
  752. // Default Bank Account
  753. if (isModEnabled("banque")) {
  754. print '<tr><td class="nowrap">';
  755. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  756. print $langs->trans('DefaultBankAccount');
  757. print '<td>';
  758. if ($action != 'editbankaccount' && $user->rights->salaries->write) {
  759. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
  760. }
  761. print '</tr></table>';
  762. print '</td><td>';
  763. if ($action == 'editbankaccount') {
  764. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
  765. } else {
  766. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
  767. }
  768. print '</td>';
  769. print '</tr>';
  770. }
  771. // Other attributes
  772. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  773. print '</table>';
  774. print '</div>';
  775. print '<div class="fichehalfright">';
  776. $nbcols = 3;
  777. if (isModEnabled("banque")) {
  778. $nbcols++;
  779. }
  780. /*
  781. * Payments
  782. */
  783. $sql = "SELECT p.rowid, p.num_payment as num_payment, p.datep as dp, p.amount,";
  784. $sql .= " c.code as type_code,c.libelle as paiement_type,";
  785. $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.currency_code as bacurrency_code, ba.fk_accountancy_journal';
  786. $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
  787. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
  788. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
  789. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
  790. $sql .= ", ".MAIN_DB_PREFIX."salary as salaire";
  791. $sql .= " WHERE p.fk_salary = ".((int) $id);
  792. $sql .= " AND p.fk_salary = salaire.rowid";
  793. $sql .= " AND salaire.entity IN (".getEntity('tax').")";
  794. $sql .= " ORDER BY dp DESC";
  795. //print $sql;
  796. $resql = $db->query($sql);
  797. if ($resql) {
  798. $totalpaid = 0;
  799. $num = $db->num_rows($resql);
  800. $i = 0; $total = 0;
  801. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  802. print '<table class="noborder paymenttable">';
  803. print '<tr class="liste_titre">';
  804. print '<td>'.$langs->trans("RefPayment").'</td>';
  805. print '<td>'.$langs->trans("Date").'</td>';
  806. print '<td>'.$langs->trans("Type").'</td>';
  807. if (isModEnabled("banque")) {
  808. print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
  809. }
  810. print '<td class="right">'.$langs->trans("Amount").'</td>';
  811. print '</tr>';
  812. if ($num > 0) {
  813. $bankaccountstatic = new Account($db);
  814. while ($i < $num) {
  815. $objp = $db->fetch_object($resql);
  816. print '<tr class="oddeven"><td>';
  817. print '<a href="'.DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a></td>';
  818. print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
  819. $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
  820. print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
  821. if (isModEnabled("banque")) {
  822. $bankaccountstatic->id = $objp->baid;
  823. $bankaccountstatic->ref = $objp->baref;
  824. $bankaccountstatic->label = $objp->baref;
  825. $bankaccountstatic->number = $objp->banumber;
  826. $bankaccountstatic->currency_code = $objp->bacurrency_code;
  827. if (isModEnabled('accounting')) {
  828. $bankaccountstatic->account_number = $objp->account_number;
  829. $accountingjournal = new AccountingJournal($db);
  830. $accountingjournal->fetch($objp->fk_accountancy_journal);
  831. $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  832. }
  833. print '<td class="right">';
  834. if ($bankaccountstatic->id)
  835. print $bankaccountstatic->getNomUrl(1, 'transactions');
  836. print '</td>';
  837. }
  838. print '<td class="right nowrap amountcard">'.price($objp->amount)."</td>\n";
  839. print "</tr>";
  840. $totalpaid += $objp->amount;
  841. $i++;
  842. }
  843. } else {
  844. print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
  845. print '<td></td><td></td><td></td><td></td>';
  846. print '</tr>';
  847. }
  848. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid")." :</td><td class=\"right nowrap amountcard\">".price($totalpaid)."</td></tr>\n";
  849. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected")." :</td><td class=\"right nowrap amountcard\">".price($object->amount)."</td></tr>\n";
  850. $resteapayer = $object->amount - $totalpaid;
  851. $cssforamountpaymentcomplete = 'amountpaymentcomplete';
  852. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
  853. print '<td class="right nowrap'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
  854. print "</table>";
  855. print '</div>';
  856. $db->free($resql);
  857. } else {
  858. dol_print_error($db);
  859. }
  860. print '</div>';
  861. print '</div>';
  862. print '<div class="clearboth"></div>';
  863. print dol_get_fiche_end();
  864. if ($action == 'edit') {
  865. print $form->buttonsSaveCancel();
  866. print "</form>";
  867. }
  868. $resteapayer = price2num($resteapayer, 'MT');
  869. /*
  870. * Action bar
  871. */
  872. print '<div class="tabsAction">'."\n";
  873. if ($action != 'edit') {
  874. // Reopen
  875. if ($object->paye && $user->rights->salaries->write) {
  876. print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
  877. }
  878. // Edit
  879. if ($object->paye == 0 && $user->rights->salaries->write) {
  880. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '');
  881. }
  882. // Emit payment
  883. if ($object->paye == 0 && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $user->rights->salaries->write) {
  884. print dolGetButtonAction('', $langs->trans('DoPayment'), 'default', DOL_URL_ROOT.'/salaries/paiement_salary.php?action=create&token='.newToken().'&id='. $object->id, '');
  885. }
  886. // Classify 'paid'
  887. // If payment complete $resteapayer <= 0 on a positive salary, or if amount is negative, we allow to classify as paid.
  888. if ($object->paye == 0 && (($resteapayer <= 0 && $object->amount > 0) || ($object->amount <= 0)) && $user->rights->salaries->write) {
  889. print dolGetButtonAction('', $langs->trans('ClassifyPaid'), 'default', $_SERVER["PHP_SELF"].'?action=paid&token='.newToken().'&id='.$object->id, '');
  890. }
  891. // Clone
  892. if ($user->rights->salaries->write) {
  893. print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&token='.newToken().'&id='.$object->id, '');
  894. }
  895. if (!empty($user->rights->salaries->delete) && empty($totalpaid)) {
  896. print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
  897. } else {
  898. print dolGetButtonAction($langs->trans('DisabledBecausePayments'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
  899. }
  900. }
  901. print "</div>";
  902. // Select mail models is same action as presend
  903. if (GETPOST('modelselected')) {
  904. $action = 'presend';
  905. }
  906. if ($action != 'presend') {
  907. print '<div class="fichecenter"><div class="fichehalfleft">';
  908. print '<a name="builddoc"></a>'; // ancre
  909. $includedocgeneration = 1;
  910. // Documents
  911. if ($includedocgeneration) {
  912. $objref = dol_sanitizeFileName($object->ref);
  913. $relativepath = $objref.'/'.$objref.'.pdf';
  914. $filedir = $conf->salaries->dir_output.'/'.$objref;
  915. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  916. //$genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
  917. $genallowed = 0; // If you can read, you can build the PDF to read content
  918. $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
  919. print $formfile->showdocuments('salaries', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  920. }
  921. // Show links to link elements
  922. /*
  923. $linktoelem = $form->showLinkToObjectBlock($object, null, array('salaries'));
  924. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  925. */
  926. print '</div><div class="fichehalfright">';
  927. $MAXEVENT = 10;
  928. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
  929. // List of actions on element
  930. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  931. $formactions = new FormActions($db);
  932. //$somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  933. print '</div></div>';
  934. }
  935. //Select mail models is same action as presend
  936. if (GETPOST('modelselected')) {
  937. $action = 'presend';
  938. }
  939. // Presend form
  940. $modelmail = 'salary';
  941. $defaulttopic = 'InformationMessage';
  942. $diroutput = $conf->salaries->dir_output;
  943. $trackid = 'salary'.$object->id;
  944. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  945. }
  946. // End of page
  947. llxFooter();
  948. $db->close();